JSF - UIInput component with no input sets String Property to empty string
I've been stuck on this issue for a while now. I found a earlier post where BalusC gave advice on creating your own converter called "EmptyToNullConverter" for JSF version 1.2 or specifying a context parameter in JSF 2.0
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
None of these options has worked for me. Has it worked for other people.
Doing some investigation of my own I ended up stepping through the UIInput source. I can see the value is null until it is passed to the ValueExpression. Unfortunately I do not have the source for that so I could not drill down further. I'm assuming it is here where it ends up instantiating a new String Type and rather passing that to the model property?
My environment is as follows
- running Mojarra RI using the jsf-api-2.0.3 and jsf-impl-2.0.3 jars
- also using richfaces 3.3.3, so I had to disable the viewhandler for jsf2. Still using 开发者_如何学编程facelets jar as a result
- All this is running on Tomcat 6
Any help will be appreciated
I know we had this problem using Richfaces and Sun's default JSF implementation 1.2. One way to work around the problem is using your own custom converters for whatever type you need that convert empty values (0, "") to nulls.
Other way is doing the conversion inside your backingbean:
MyBackingBean { String myValue; public void setMyValue(String v) { if (v==null || v.trim().length==0) { myValue==null; } else { myValue=v; } } public String getMyValue() { return myValue; } }
精彩评论