无法为passthrough属性访问f:selectItems变量

时间:2016-05-27 06:24:37

标签: jsf selectonemenu passthrough-elements

我正在使用JSF 2.2,我希望在title使用 passthrough 生成的每个option元素上显示h:selectOneMenu属性,方法是使用f:selectItems变量。

我似乎无法访问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>

问题是我无法访问item的{​​{1}}变量,输出只是空的。

以下是生成的代码

p:title

是否可以这样做或有其他方式吗?

1 个答案:

答案 0 :(得分:1)

我终于使用jstl c:forEach循环找到了我的问题的解决方案Using f:selectItems var in passtrough attribute

以下是代码:

f:selectItem