I just came across Best way to add a "nothing selected" option to a selectOneMenu in JSF and I was wondering how to (best) implement a p:selectOneMenu
that gets included via ui:include
and gets an option to say whether the component is to display a null (Please select...) entry or not:
<p:selectOneMenu id="#{id}"
value="#{value}"
converter="#{not empty converter ? converter : idEntityConverter}"
required="#{not empty required ? required : false}"
requiredMessage="#{not empty requiredMessage ? requiredMessage : commontext['message.required']}"
hideNoSelectionOption ????
rendered="#{commonf:isAllowed(not empty allowed ? allowed : true, benutzerRecht)}"
disabled="#{not empty disabled ? disabled : false}">
<f:selectItem itemValue="#{null}" itemLabel="#{commontext['common.action.pleaseSelect.label']}" noSelectionOption="true" />
<f:selectItems value="#{selectableEntities}"
var="ent"
itemValue="#{ent}"
itemLabel="#{not empty labelExpression ? labelExpression : ent}"
itemDisabled="#{not empty disabledExpression ? disabledExpression : false}" />
</p:selectOneMenu>
As the aforementioned SO posting shows, the standard JSF h:selectOneMenu
way is to use the hideNoSelectionOption
attribute, which is missing in the p:selectOneMenu
.
Q:
Since f:selectItem
is a tag handler the question is: how do you tell the above component that if the field is required, that the p:selectOneMenu
shall not render the noSelectionOption f:selectItem
(disabling it is not desired)?
The question has already been raised a long time ago without an answer in the PrimeFaces forum here: https://forum.primefaces.org/viewtopic.php?t=8028