< f:selectItems itemDescription>不起作用 [英] <f:selectItems itemDescription> does not work

查看:144
本文介绍了< f:selectItems itemDescription>不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码

<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>标签中不起作用.

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

是这里的错误吗?

推荐答案

f:selectItems需要一个您在我们的bean中定义的列表,如下所示:

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"));

如果这样做,您甚至不需要itemValue或itemDescription,因为它已在列表中定义.

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

更新(注意:您不需要itemValue,itemDescription):

在您的xhtml页面中,它看起来像这样:

In your xhtml page it would look like this:

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

这篇关于&lt; f:selectItems itemDescription&gt;不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆