my dog learned polymorphism*
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
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Null first value in a SelectOneMenu