I am working with JSF 2.0, JBoss 7.1.1 Final, and I have the following problem with selectOneMenu. I want to be able to set the field in the managed bean to true / false / null. So I created the following selectOneMenu:
<h:selectOneMenu value="#{personList.criteria.registrationComplete}" > <f:selectItem itemValue="#{null}" itemLabel="Any.." /> <f:selectItem itemValue="true" itemLabel="Yes"/> <f:selectItem itemValue="false" itemLabel="No"/> </h:selectOneMenu>
Now, if I select βAny ..β, it will assign βfalseβ to the registrationComplete field (which is logical). Therefore, null is interpreted as false . I also tried using booleans in selectItem (s), namely:
<h:selectOneMenu value="#{personList.criteria.registrationComplete}" > <f:selectItem itemValue="#{null}" itemLabel="Any.." /> <f:selectItem itemValue="#{true}" itemLabel="Yes"/> <f:selectItem itemValue="#{false}" itemLabel="No"/> </h:selectOneMenu>
And I also registered the converter in faces-config as follows:
<converter> <converter-id>booleanConverter</converter-id> <converter-class>javax.faces.convert.BooleanConverter</converter-class> </converter>
and tried to use it:
<h:selectOneMenu value="#{personList.criteria.registrationComplete}" > <f:selectItem itemValue="#{null}" itemLabel="Any.." /> <f:selectItem itemValue="true" itemLabel="Yes"/> <f:selectItem itemValue="false" itemLabel="No"/> <f:converter converterId="booleanConverter"/> </h:selectOneMenu>
But all these attempts led to the same behavior - when a zero value was chosen, it was interpreted as false.
I debugged it and in the stack trace I found a place where this happens. In AstValue.setValue(EvaluationContext, Object) line: 204
he calls
ELSupport.coerceToType(value, targetClass)
Parameter
value is null and targetClass is boolean. This coerceToType method returns false.
Any ideas how to solve these problems? Thanks!
boolean el jsf-2 selectonemenu
lukas
source share