1

私は JSF 2.2 を使用しており、変数の属性を使用してパススルーtitleで生成された各option要素に属性を表示したいと考えています。h:selectOneMenuf:selectItems

パススルー属性f:selectItemsをカスタマイズするための変数にアクセスできないようです

これが私がこれまでに行ったことです

表示するエンティティ

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
}

エンティティのリストを取得するためのバックビーン メソッド

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問題は、の変数にアクセスできないことp:titleです。出力は空です。

生成されたコードは次のとおりです

<select>
    <option title="Description : " value="1">Java</option>
    <option title="Description : " value="2">PHP</option>
    <option title="Description : " value="3">Python</option>
</select>

そのようにすることは可能ですか、それとも別の方法がありますか?

4

1 に答える 1

1

私はついにjstl c:forEachループを使用して問題の解決策を見つけました。f:selectItemこの投稿からUsing f:selectItems var in passtrough attribute

コードは次のとおりです。

<h:selectOneMenu>
    <c:forEach items="#{bean.items}" var="item">
        <f:selectItem itemValue="#{item.id}"
                      itemLabel="#{item.strName}"
                      p:title="Description : #{item.strDescription}"/>
    </c:forEach>
</h:selectOneMenu>
于 2016-05-28T15:48:20.667 に答える