问题
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