aspose file tools*
The moose likes JSF and the fly likes Null first value in a SelectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Null first value in a SelectOneMenu" Watch "Null first value in a SelectOneMenu" New topic
Author

Null first value in a SelectOneMenu

Anoop V. Kumar
Greenhorn

Joined: Jan 21, 2006
Posts: 18
I have implemented a SelectOneMenu which displays some ids as the label and the value contained are actual objects that I have created. The objects are my business objects and non-string. It works fine.

Now I wanted to include the first item in the SelectOneMenu as: "Choose one" with a null or "" value - but I get NullPointerException.

Here is the jsp:

<h:selectOneMenu id="selectedModel"
value="#{modelBean.selectedModel}"
converter="#{modelBean.convert}"
onchange="this.form.submit();"
>
<f:selectItem itemLabel="Choose a model" itemValue=""/>
<f:selectItems value="#{modelBean.models}" />
</h:selectOneMenu>

I have made changes in my converter to return a null Model object if the value is "". (this was after I started getting ClassCastExceptions) But still doesnt work.

Also - in my logs I see that it is calling my converter's getAsString - should it not be calling the getAsObject method??

Has anybody managed to include a null value in a selectOneMenu which takes actual objects for the values?? Please let me know how you have done it

Thanks,
Anoop
 
Consider Paul's rocket mass heater.
 
subject: Null first value in a SelectOneMenu