Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following selectOneMenu and within of my component I want to have an item which shouldn't be shown, for e.g. in cases where the value from #{Mybean.value} match a value from #{Mybean.ListValues} I don't want to have an empty option in my combo box .

  <p:selectOneMenu value="#{Mybean.value}"  hideNoSelectionOption="true"     
   required="true" requiredMessage="Required data">

      <f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
      <f:selectItems value="#{Mybean.ListValues}" var="option"  itemLabel="#{option.optionName}"   
      itemValue="#{option.optionId}"/>
 </p:selectOneMenu>

I searched, but I didn't find anything useful, just one link in primefaces forum where describes exactly this problem.

My primefaces version is 3.5

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
802 views
Welcome To Ask or Share your Answers For Others

1 Answer

Edit: it is supported from version 9 and on, see the other answer.

That attribute doesn't exist in the official api or in the doc. Where did you get it from?


What you're actually looking for is the itemDisabled attribute on the f:selectItems component. It's this attribute that disables a selectItem from being selected. Historically, primefaces has had problems with that attribute.

Ideally, you should have

   <p:selectOneMenu value="#{Mybean.value}" required="true" requiredMessage="Required data">
       <f:selectItem itemLabel="" itemValue="#{null}" noSelectionOption="true" />
       <f:selectItems itemDisabled="#{Mybean.value=='aValue'}" value="#{Mybean.ListValues}" var="option" itemLabel="#{option.optionName}"      itemValue="#{option.optionId}"/>
  </p:selectOneMenu>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...