Provide a wildcard f:selectItem value in p:selectOneMenu with dynamic data and Converter

痞子三分冷 提交于 2019-12-11 19:22:16

问题


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" />

来源:https://stackoverflow.com/questions/17611980/provide-a-wildcard-fselectitem-value-in-pselectonemenu-with-dynamic-data-and-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!