p:selectOneMenu and parameterizable noSelectionOption (required = true), hideNoSelectionOption missing [duplicate] - jsf

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

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>

hideNoSelectionOption implemented in PrimeFaces 9.0
Issue: https://github.com/primefaces/primefaces/issues/5886
PR: https://github.com/primefaces/primefaces/pull/5909

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"

Related

Custom p:radioButton does not work inside a table: id of select not found

I have a table, and I want to put inside any row of this table a custom p:radioButton, on two different columns.
This is the code of the p:selectOneRadio:
<p:selectOneRadio
value="#{bean.val}"
id="val"
required="true"
layout="custom"
>
<f:selectItem itemLabel="" itemValue="A" />
<f:selectItem itemLabel="" itemValue="B" />
</p:selectOneRadio>
and this is the code of one of the radioButton:
<p:radioButton for="tabs:table:#{i}:val" itemIndex="0"/>
I checked with the browser and the id is right. Anyway, I get this error:
javax.faces.FacesException: Cannot find component 'tabs:table:0:val' in view.
What could be the problem? Please help :)
I'm using Primefaces 3.4.1 with Mojarra 2.1.7
Well, the solution was simple, and it was suggested to me by BalusC:
<p:radioButton for="val" itemIndex="0"/>

hideNoSelectionOption in selectOneMenu is not working as expected

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
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>
hideNoSelectionOption implemented in PrimeFaces 9.0
Issue: https://github.com/primefaces/primefaces/issues/5886
PR: https://github.com/primefaces/primefaces/pull/5909
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"

p:watermark clears on updating Component even if there is no value

I'm using Primefaces p:watermark on a p:inputText. Its working fine.
When ever I update the component its loosing watermark,even when there is no content inside the p:inputText
<h:form id="reg_frm">
<p:inputText id="name" value="#{user.name}"/>
<p:watermark value="your name" for="name" id="name_watermark" />
<p:selectOneMenu value="#{user.drpvalue}">
<f:selectItem itemLabel="One" itemValue="1"/>
<f:selectItem itemLabel="two" itemValue="2"/>
<f:selectItem itemLabel="three" itemValue="3"/>
<f:selectItem itemLabel="four" itemValue="4"/>
<p:ajax event="change" update="name name_watermark"/>
</p:selectOneMenu>
</h:form>
How do I retain the Watermark when there is no content in the
p:inputText after update?
Note: Primefaces version - 3.5
According to the PrimeFaces showcase for watermarks: "Watermark displays a hint about input fields by using native placeholder in supported browsers and a javascript solution in others browser compatibility."
PrimeFaces probably adds some hidden javascript stuff to the element which is a parent of both components (input and watermark). In your case that's the form which you would need to update. If you don't want that, put a new panelgroup around both elements and update that, which will have the same effect.
Try this attribute:
oncomplete="PrimeFaces.showWatermarks()"
It was given in Primefaces User's Guide.

<p:selectOneMenu> getting null on submit/next

I am using primefaces wizard. During wizard flow all parameters saved correctly . However <p:selectOneMenu> items getting NULL on submit.Also on 'back', it will not show what I have selected. Same for <p:selectManyMenu> also. Any solution ?
Here is the code snippets.I'm using primefaces-3.0.M3 and jsf2.
<h:outputText value="Employee Status" />
<p:selectOneMenu id="employeeStatus"value="#{employeeRepositoryImpl.employeeStatus.title}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Permanent" itemValue="Permanent" />
<f:selectItem itemLabel="Contract" itemValue="Contract" />
<f:selectItem itemLabel="Part-Time" itemValue="Part-Time" />
<f:selectItem itemLabel="Training" itemValue="Training" />
</p:selectOneMenu>
<p:message id="employeeStatusId" for="employeeStatus" />
This is in a <p:wizard> tab, while clicking next button or submit button, the itemValues getting null.Sorry for the re-post.
Have you deleted the previous post?
Anyway, firstly, you should upgrade to Primefaces 3.0.M4!
Secondly, it would be better to use a list along with f:selectItems and all those String values to be stored in a list(this way you have more control over what's in the list and what should the list return), but if you want to stick with f:selectItem try using it with the enclosing tag (it may be a bug without it):
<f:selectItem itemLabel="Permanent" itemValue="Permanent" ></f:selectItem>
Also, I repeat myself, upgrade to Primefaces 3.0.M4!
I have solved it by using primefaces AJAX
<p:ajax update="employeeStatus" listener="#{employeeRepositoryImpl.employeeStatusAjax}" />
inside my </p:selectOneMenu> and I check/process this in side employeeStatusAjax().

noSelectionLabel in jsf?

There are many situations when we want to tell the user to select an option from a selectOneMenu component. In Seam this is easily solved using noSelectionLabel.
<h:selectOneMenu value="#{seasonHome.id}">
<s:selectItems value="#{seasonListQuery.resultList}"
var="season"
label="xxxSeason #{season.startYear}"
noSelectionLabel="Select Season"
hideNoSelectionLabel="true" />
<s:convertEntity />
</h:selectOneMenu>
Can you please tell me if there is something similar in JSF 1.2?
I'm using icefaces with a list for selectItems like:
<ice:selectOneMenu
id="#{id}"
required="#{required}"
styleClass="#{styleClass} #{not required ? 'graNotRequired':''}"
style="width: #{width};font-size: #{fontSize};"
partialSubmit="#{partialSubmit}"
disabled="#{disabled}"
value="#{fieldOneDataHolder[fieldTwo]}">
<f:selectItems value="#{selectableItems}" />
<f:validator validatorId="#{validatorId}" />
</ice:selectOneMenu>
(please ignore parameters, this is a custom component I made).
I can introduce a new <f:selectItem itemLabel="Please select" itemValue=""/> above f:selectItems but this is difficult (I have to find a way to hide it in some cases etc)...
Do you know other work-around?
Thanks.
<f:selectItem itemLabel="Please select" itemValue="" itemDisabled="true" rendered="#{isShown}" />
The itemDisabled will make it shown but not selectable.
The boolean in rendered will decide whether the item is shown or not.

Resources