I have a <p:selectOneMenu>
component, that is fed with an Array of instances of some Class (say ClassABC). In the top of the selectItems list, I want to provide a <f:selectItem>
that will serve as a Wildcard/Any option, and it's value should be a null object.
I managed to make this work as
<p:selectOneMenu
value="#{someBean.selectedInstance}"
converter="classABCDConverter" >
<!-- Wildcard Value -->
<f:selectItem itemLabel=" * Any * " itemValue="" />
<!-- Dynamic Data with Real Instances -->
<f:selectItems
var="result"
value="#{someBean.arrayOfInstancesOfClassABCD}"
....
/>
</p:selectOneMenu>
So far this seems to work, as selecting the -any- select item, gives a null Object to someBean.selectedInstance
. I guess that itemValue=""
makes the Converter return a null object, so it probably looks legit.
But I'm just curious if this is the safest and most efficient way to go.
EDIT: Alternatively I could use noSelectionOption="true"
so, for example, which would be better from the 2 bellow :
<f:selectItem itemLabel=" * Any * " itemValue="" />
or
<f:selectItem itemLabel=" * Any * " noSelectionOption="true" />