Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

h:selectOneMenu values customization

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 28054
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic