I am getting an error message in my JSF pages... Conversion error setting value 'delovenier' for 'null converter', where delovenier is the name of the chosen project.
I'm not sure why this is happening. Could someone please assist me.
This is my JSF code...
<h:selectOneListbox id="proj" value ="#{studentEController.gekozenProject}">
<f:selectItems value="#{studentEController.projecten}"></f:selectItems>
</h:selectOneListbox>
And this is my code in the managedBean StudentEController.
private List<ProjectE> projecten;
private ProjectE gekozenProject;
As you can see, they have the same type of ProjectE.
Data transferred between the server and the client will be in string form.
The Expression Language can coerce a set of standard types (ints, etc.), but for complex types you are going to have to add a Converter to your component. Your converter will serialize ProjectE types to strings at render time and deserialize them to new ProjectE instances when forms are submitted.
You can create converters for specific types or add them explicitly to components.
See Creating a Custom Converter in the Java EE 6 tutorial and the <f:converter> tag.
Related
When editing an Input Field and trying to add a Validator I get this error:
The validator field I'm talking about
Cannot convert class java.util.LinkedHashSet to class java.lang.String
I understand the error but not sure how to fix it.
Did anyone run into this problem and how did you fix it?
My magnolia version: 5.4.6
Thanks!
If I guess the context correctly, this validation field is from the Form module; more precisely it is a Twin-column field, configured in the formEdit dialog.
The "Cannot convert class" error usually occurs when the Vaadin field is incompatible with the Magnolia/JCR property it's trying to save to.
Use the JCR Browser app to see (and delete) if there is any pre-saved String value for the validation property of this component. Well-formed "multi-values" are displayed within square brackets, e.g. [email].
I could not reproduce this error on the Magnolia Demo—currently running 5.6.3, so if the above doesn't solve it, this could come from the dialog/field configuration, if you use a custom one. As a reference, the formEdit dialog is configured at:
/modules/form/dialogs/formEdit/form/tabs/tabMain/fields/validation.
I have a web application wrote in Spring. There is a HTML form with one Integer field. I added a custom message for typeMismatch.java.lang.Integer and it is correctly handled but there is one issue. Spring does not distinguish between a string value and "overflowed" integer. In other words - there is no difference whether user enter this is a string or 1000000000000000000000000000. Both are handled by Spring as typeMismatch. I would like to have two separate messages for both cases.
I thought about two solutions:
replace the java.lang.Integer by java.math.BigInteger in the
form object - then the typeMismatch error will apply only to this
is a string and I will handle 1000000000000000000000000000 in a
validator
register my own property editor for Integer, but I'm not sure if I
could handle two different errors with one property editor
Do you have any better concepts for this issue?
Could you integrate the hibernate validation framework / Java EE6 bean validation into your Spring project?
You could then limit the acceptable range allowed for your integer field with an annotation such as :
#Min(1)
#Max(10000)
private Integer myInteger;
Here is an easy to follow article :
http://www.c-sharpcorner.com/UploadFile/5fd9bd/javax-annotation-and-hibernate-validator-a-pragmatic-appro/
I am working on "migration from JSP to FLEX, and java as back-end. I am novice in java and JSP.
I am stuck at getting values from a java servlet where it takes httprequest and there is a function called forward(request,response) which responds as JSP page with requried values in it.
Now I need to change that and get only data from that servlet and use that in flex.
Problem:
case1: When using httpservice it takes result as string, but unable to get as object.
case2: If I use RemoteObject , it needs method in java servlet to get return value, which is not present in existing servlet.
Can I get any suggestions on this problem.
Thank You
case1: you don't use forward anymore, you set the type of data you want to return, for example:
response.setContentType("application/json");
... and returning data in servlet is done by writing data to a stream like:
PrintWriter out = response.getWriter();
out.print(object);
but it's a while ago since I did this, so there may be some small problem you will face...
case2: if you are using servlet, it's correct to use HTTPService, RemoteObject will not work, it is used differently....
Now, if I can, I would suggest diferent thing to use than servlets - to obtain data from a java server to Flex - I love to use GraniteDS.
I will just state some benefits I see, in case you are interested:
It is easy to setup:
- in java, you will just add a graniteDS library, two config files (granite+services-config xmls) add a granite servlet config to web.xml
- in flex there is also granite library and services-config.xml
When set up, using it is also flowleslly easy - you have a class with a method (or simple bean or ejb) in Java which just return an object of any type! And that's it in Java
In flex, in this case you use RemoteObject which you just call that remote java method and in result handler you get your dataGranite will take care of serializing+transfer+deserializing and just give you the Object (either just dynamic {} or even exact class type)
I have a customized JSP tag library with a Java class (extending TagSupport) that generates the output for my web application. It has some parameters that are formed into HTML code using a StringBuilder.
Now the generated HTML is becoming more complex and hard to handle with calls of StringBuilder.append, so I'd like to replace the code generation with a Freemarker template.
I already found out that I could use a generic Struts component tag instead, because the Struts tags already use Freemarker template files, so I could write a tag like:
<s:component template="/components/myStruct.ftl">
<s:param name="myParam" value="%{'myParam'}" />
</s:component>
Then writing the specified template file myStruct.ftl would probably solve my problem. I actually did not try if Struts really finds and uses that file correctly, but I optimistically expect it to work.
My question is, if it's also possible to retain the current code with the customized tag
<my:struct param="myParam" />
and only change the Java class linked to that tag.
I've found code that reads a Freemarker template:
Configuration config = FreemarkerManager.getInstance().getConfiguration(pageContext.getServletContext());
config.setServletContextForTemplateLoading(pageContext.getServletContext(), "/components");
Template templ = config.getTemplate("myStruct.ftl");
templ.process(params, pageContext.getOut());
but it seems very circuitously to me and I wondered what would be the "standard" way to do it. Additionally it seemed that you cannot use tags from the Struts tag library in a template used like this. (I ran into an ArrayIndexOutOfBoundException, caused by Sitemesh... I did not analyze it yet.)
My intention was to keep the Java class as some kind of wrapper around the Struts component tag. Maybe somthing like:
OgnlValueStack stack = TagUtils.getStack(pageContext);
Component c = new Component(stack);
c.addParameter("param", param);
But I don't know how to continue this code stub. It may be crap anyway.
Is there an easy/"standard" way to do this or do I simply have to get rid of the customized tag?
Thanks in advance.
A friend of mine sent me this link:
http://cppoon.wordpress.com/2013/02/27/how-to-create-a-struts-2-component-with-freemarker/
This is what I was looking for. The gist is to change the customized tag to not extend TagSupportbut AbstractUITag which makes it a Struts tag instead of a JSP tag, roughly speaking.
This enables the automatic linkage (by name and path conventions) to my Freemarker template. I basically followed the instructions on that page. I only added the methods that are abstract in the super class, so they had to be implemented.
IMO the site lacks of a description of how the UI bean class is linked to the tag class. But as the IDE forces you to implement the getBean method inside the tag class, you quickly get to this code (using the classes described on that site):
#Override
public Component getBean(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response)
{
Pagination pagination = new Pagination(stack, request, response);
pagination.setList(list);
return pagination;
}
This might not be completely correct for the recent Struts, but it worked for the ancient version I've got to use.
Thanks again to the guy who sent me the link :)
I have a spring bound form (modelAttribute) which displays the user information.
The user's telephone number is displayed in a formatted manner but a requirement is that the number is saved to the database without any signs.
So in the getter method of my user object I format the telephone number according to the rules and in the setter I put the code to remove the special signs.
The formatting part works fine, but setter part where I remove the signs does not seem to occur.
In my constructor I also did:
setTelephoneNumber(TelephoneNumber);
So the constructor also invokes the setter.
I'm using Spring 3.0.4 and Spring-mvc.
Any input on this issue and how to resolve it would be appreciated.
edit:
controller section:
model.addAttribute("user", user);
JSP (shortened it a bit but this is the gist. submitUrl is due to a portal environment:
<form:form action="${submitUrl}" modelAttribute="user">
<form:input path="telephoneNumber"/>
</form>
Model telephoneNumber setter:
if(!StringUtils.isBlank(telephoneNumber)){
this.telephoneNumber = telephoneNumber.replaceAll("[^0-9]", "");
} else{
this.telephoneNumber= "";
}
And I think so because the value lands in the database with the formatting I used. (spacing)
Even if it is not the correct answer to your question:
I strongly recommend to do the formating in an other way then by setter getter
Spring 3.0 provideds something they called "type conversion"
spring blog with example
spring reference "Validation, Data Binding, and Type Conversion"
Using this would be much more cleaner.
Back to your question:
Spring path binding: is it bound directly to the variable or does it invoke the constructor/setters?
As fare I understand the Java Doc and some code snippets, Spring uses BeanWrapper (BeanWrapperImpl) to set the values of Beans (#see Reference: 5.4 Bean manipulation and the BeanWrapper). And BeanWrapperImpl behaves like the reference said:
uses setter and getter to access "simple" values.
It is exactly like the reference said in section "5.4.1 Setting and getting basic and nested properties": For an expression "name":
Indicates the property name
corresponding to the methods getName()
or isName() and setName(..)
So at least this answer your question, so I assume that the cause for your problem is some thing else.