• 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

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: 27763
196
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.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic