我有代码
<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>
此处itemDescription="TEST"
属性在<f:selectItem>
代码中运行良好。但itemDescription="#{ds.description}"
无效<f:selectItems>
代码。
这是虫子吗?
答案 0 :(得分:1)
f:selectItems需要一个你在我们的bean中定义的List,如下所示:
List<SelectItem> list = new LinkedList<SelectItem>();
list.add(new SelectItem("this will be the return value -> itemValue", "this will be the display value -> itemLable"));
如果这样做,您甚至不需要itemValue或itemDescription,因为它已在列表中定义。
更新(注意:您不需要itemValue,itemDescription):
在您的xhtml页面中,它看起来像这样:
<p:selectOneMenu value="#{reportRegisterManagedBean.starter}">
<f:selectItems value="#{reportRegisterManagedBean.startersSelectItems}" />
</p:selectOneMenu>