Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enum with selectItems

 
Ryan Slominski
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When working with an enum in a "pick an item from this list" kind of component such as a selectOneMenu it would be nice to not have to create a utility method to map the enum values to an array of SelectItems. When working with a List of objects you can take advantage of the var, itemLabel, and itemValue attributes of the selectItems component (and thus avoid the silly utility method). This doesn't seem to work with the array of values available with the enum.

Maybe the value attribute can only be a collection, not an array if you intend to iterate over the items using var, itemLabel, and itemValue?

I've read through this post: JSF-Populate-SelectOneRadio-Enum-values, but it makes no mention of the var, itemValue, or itemLabel attributes.
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make a selectItem list for an enum, you can build a list or array or SelectItem (enum.ordinal(), enum.name()). That's about as simple as you can get for a construct with no "get" methods.

Or actually, I think it's "SelectItem(enum, enum.name()).
 
Ryan Slominski
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am understanding your response correctly you are saying that there is no way to avoid a utility method with an enum?

I'm currently using a utility method, but I was wondering if there was a better way since there is a shortcut for a collection (var attribute).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!