• Post Reply Bookmark Topic Watch Topic
  • New Topic

h:selectOneMenu values customization  RSS feed

 
Anantha Ramachandra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a select one menu with a selectedItem ( labelled as "ALL") and a list of selectedItems from the managed bean. How do I hide the select option "ALL" when there is only one selected item in the selectedItems list, by making changes to the web page ( through JSF expression or Javascript) only.

example:

<h:selectOneMenu id="stationId" value="#{manageBagIrregularitiesBean.flightQueryInfo.station}" tabindex="1">
<f:selectItem value="ALL"/>
<f:selectItems value="#{flightInfoBean.userStations}" />
</h:selectOneMenu>

"ALL" needs to be hidden if flightInfoBean.userStations list has only one value, changes to the backing bean's java code is not allowed.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In theory, you could set the "itemDisabled" attribute based on the EL-computed length of the selectItem list. In practice, apparently itemDisabled isn't very reliable, and the actual documented behavior doesn't guarantee hiding that item (it could grey it out, for example). "f" elements, unfortunately, are modfiers, so there's no "rendered" attribute"

Probably the most reliable, if not pleasant, way to do this is make 2 copies of the control, one with the "ALL" selectItem, one without and set up their respectived rendered= attributes to display the desired one based on the length of the selectItem list.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!