1

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

Mindwin Remember Monica
  • 1,469
  • 2
  • 20
  • 35
unpix
  • 853
  • 2
  • 15
  • 31

3 Answers3

3

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>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • Thank you for your answer @kolossus , in fact the attribute **hideNoSelectionOption** doesn't seem to be in primefaces 3.5, I got it from http://stackoverflow.com/questions/11360030/best-way-to-add-a-nothing-selected-option-to-a-selectonemenu-in-jsf/11397505#11397505 and also from the link I posted before. – unpix Oct 09 '14 at 07:40
  • 2
    The link you've referenced is referring to the **``** not **``** that you're trying to use @unpix; they're not the same and they're not interchangeable – kolossus Oct 09 '14 at 11:44
  • You are right @kolossus, thanks. Since in my schema, h refers to JSF and p to PrimeFaces. So basically the answer to my question is here. I will mark as it is solved. Thanks – unpix Oct 09 '14 at 11:57
2

hideNoSelectionOption implemented in PrimeFaces 9.0

Issue: https://github.com/primefaces/primefaces/issues/5886

PR: https://github.com/primefaces/primefaces/pull/5909

Melloware
  • 10,435
  • 2
  • 32
  • 62
-2

So, basically and based on @kolossus answer, we can in primefaces (when you are using <p:selectOneMenu...) case add the following empty item

<f:selectItem itemValue="#{null}" itemLabel="--select--"  itemDisabled="#{Mybean.value ne null}" />

We can in primefaces (when we have to use

Note: In such case we don't need the following two tags:

hideNoSelectionOption="true"

and

noSelectionOption="true"
A. Qaoud
  • 33
  • 2
  • Why not just add this as a comment or small edit to the question? – Kukeltje Jul 19 '17 at 12:07
  • I'm new on stackoverflow and I don't have enough reputation to comment on others posts.Thanks for the "-1" anyway...@Kukeltje – A. Qaoud Jul 19 '17 at 12:31
  • This post does not answer the question at all. Read the first paragraph of the question once more. – BalusC Jul 19 '17 at 16:29
  • @BalusC : I tried the solution proposed by Kukeltje but it didn't work.It worked is when I moved itemDisabled attribute to – A. Qaoud Jul 20 '17 at 09:28