【发布时间】:2016-05-27 06:24:37
【问题描述】:
我正在使用 JSF 2.2,并且我想通过使用 f:selectItems 变量的属性在 h:selectOneMenu 生成的每个 option 元素上显示一个 title 属性,并使用 passthrough。
似乎我无法访问 f:selectItems 变量来自定义我的 passthrough 属性
这是我到目前为止所做的事情
我要显示的实体
public class ItemBean {
private int id;
private String strName;
private String strDescription;
public ItemBean(int id, String strName, String strDescription) {
this.id = id;
this.strName = strName;
this.strDescription = strDescription;
}
// Getters and Setters
}
我的 backbean 方法来检索实体列表
public List<ItemBean> getItems() {
return new ArrayList<ItemBean>(){
{
add(new ItemBean(1, "Java", "Java programming language"));
add(new ItemBean(2, "PHP", "Yet another language"));
add(new ItemBean(3, "Python", "Not a snake at all"));
}
};
}
我的h:selectOneMenu在视图中
<h:selectOneMenu>
<f:selectItems value="#{bean.items}" var="item"
itemValue="#{item.id}"
itemLabel="#{item.strName}"
p:title="Description : #{item.strDescription}"/>
</h:selectOneMenu>
问题是我无法访问p:title 的item 变量,那里的输出只是空的。
这是生成的代码
<select>
<option title="Description : " value="1">Java</option>
<option title="Description : " value="2">PHP</option>
<option title="Description : " value="3">Python</option>
</select>
是否可以这样做或有其他方法?
【问题讨论】:
标签: jsf selectonemenu passthrough-elements