Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selectItem null  RSS feed

 
gary stines
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In creating a selectOneMenu item I am using a child selectItems tag. How can I bring in the concept of a null value or a 'no selection option'. In other words can one of my selectItem objects look like this

new SelectItem(null,"none").

When I tried the above code I get a nullPointerException when rendering the page.
 
Josh Juneau
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you must use a String value...try new selectItem(" ", "NONE");

This has worked for me...

Josh
 
gary stines
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought about that. But I guess I would have to test for the empty string and then manually set the backing bean attribute to null, or does jsf automatically convert an empty string value to null? Also how would you handle other values other than a string

eg new SelectItem(new BigDecimal(0), "none")

0 could be a possibly selection value for my list.
 
Josh Juneau
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have usually just converted Strings into Integers when I had this situation. In other words, I would use the selectItem as a String, but in the bean I'd convert it with Integer.parseInt(myvalue). Never used another data type, but I cannot see why you would not be able to do so.

Regards-

Josh
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!