<f:selectItems itemDescription> does not work

不问归期 提交于 2019-12-12 00:57:17

问题


I have there code

<p:selectOneMenu id="starter" value="#{reportRegisterManagedBean.starter}" style="width:160px" converter="#{reportStarterConverter}">
<f:selectItem itemLabel="Select Report Starter" itemValue="0"
itemDescription="TEST" />
<f:selectItems
value="#{reportRegisterManagedBean.startersSelectItems}" var="ds" itemLabel="#{ds.name}" itemValue="#{ds}" itemDescription="#{ds.description}" />
</p:selectOneMenu>

here itemDescription="TEST" atribute works very well in <f:selectItem> tag. but itemDescription="#{ds.description}" not working in <f:selectItems> tag.

is here bug?


回答1:


f:selectItems requires a List which you define in our bean like this:

List<SelectItem> list = new LinkedList<SelectItem>();
list.add(new SelectItem("this will be the return value -> itemValue", "this will be the display value -> itemLable"));

If you do so, you don't even need itemValue or itemDescription, because it's already defined in the list.

Update(note: you don't need itemValue, itemDescription):

In your xhtml page it would look like this:

<p:selectOneMenu value="#{reportRegisterManagedBean.starter}">
    <f:selectItems value="#{reportRegisterManagedBean.startersSelectItems}" />
</p:selectOneMenu>


来源:https://stackoverflow.com/questions/15608843/fselectitems-itemdescription-does-not-work

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