Hi, I'm retrieving some values from 5-6 <h:selectOneMenu> in my form, the user is able to not select values from all the <h:selectOneMenu> or in some cases a <h:selectOneMenu> should have the attribute disabled="true". In both of the cases, when the user submits the form, I got the same interval server error , and Null pointer Exception.
I tried to handle and catch the null values, or I tried to declare the attribute itemValue=" " in <h:selectOneMenu>, but I couldn't solve the problem,
Any ideas on how to avoid these exceptions of non-selected options of a <h:selectOneMenu>? or due to the disabled="true" of <h:selectOneMenu>?
There is no such thing as "not selected" in an HTML SELECTITEM (which is what backs the selectOneMenu). Something will be selected. And in the case of JSF, if the something isn't one of the SelectItem values, you'll fail with a Validation Exception.
My usual approach is this:
HTML is a text protocol, so if this control is submitted, it will be set to a non-null value. By setting "required=true", I told JSF to fail cases where no item was selected. If I had not added that constraint, the myBean selection value would be the empty string ("") if no selection had been made. Outbound, a null value will cause the first item on the list to be selected, so the value would go out as null and come back as "". Which is dicey, so you're better off pre-initializing the selection value to "", instead.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Mar 11, 2012
Thank you for the reply Tim Holloway,
I found an answer for my problem in a similar way, thank you again for your useful advices.