• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to handle the situation if nothing selected from <h:selectOneMenu> and is permitted

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>?


Please I need help.
Thank you
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
michael nik
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic