h:selectOneMenu with boolean items doesn't work with null value

Viewed 12335

I'm working with JSF 2.0, JBoss 7.1.1 Final and I have following problem with selectOneMenu. I want to be able to set a field in a managed bean to true/false/null. Thus, I have created 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 choose to 'Any..', it will assign "false" to the registrationComplete field (which is Boolean). So null is interpreted as false. I also tried to use boolean values in the selectItem(s), that is:

 <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 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 resulted in the same behavior -- when the null value was selected, it was interpreted as false.

I debugged it and in the stack trace I found the location where it happens. In AstValue.setValue(EvaluationContext, Object) line: 204

it calls

ELSupport.coerceToType(value, targetClass)

value parameter is null and targetClass is Boolean. This coerceToType method then returns false.

Any ideas how to solve this issues? Thanks!

1 Answers
Related