简体   繁体   English

ui:repeat中的f:selectItem-不起作用

[英]f:selectItem inside ui:repeat - doesn't work

I want to loop through List and make each element a checkbox. 我想遍历列表并使每个元素成为一个复选框。 The code which i have is: 我拥有的代码是:

<h:outputText value="Choose" />
<p:selectManyCheckbox value="#{filterTypeBean.selectedFilterTypes}">
    <ui:repeat var="checkbox" value="#{filterTypeBean.listFilterTypes()}"
        varStatus="status">
        <!-- <h:outputText value="#{checkbox.filterTypeName}" /> -->
        <f:selectItem itemLabel="#{checkbox.filterTypeName}"
            itemValue="#{checkbox}" />
    </ui:repeat>
</p:selectManyCheckbox>

My bean class contains: 我的bean类包含:

private List<FilterType> selectedFilterTypes;

public List<TFilterType> getSelectedFilterTypes() {
        return selectedFilterTypes;
}

public void setSelectedFilterTypes(List<TFilterType> selectedFilterTypes) {
    this.selectedFilterTypes = selectedFilterTypes;
}

public List<FilterType> listFilterTypes() {
        EntityManager em = HibernateUtil.getEntityManager();
        Query q = em.createQuery("select u from FilterType u");
        List<FilterType> filterList = q.getResultList();
        for (FilterType filterType : filterList) {
            System.out.println(filterType.getFilterTypeName());
        }
        return filterList;
    }

I don't got the expected result - no checkboxes appear in the filterList (I have nothing on the screen).If i uncomment the line for printing the names of Filter Type --> I got the names. 我没有得到预期的结果-filterList中没有复选框出现(我的屏幕上没有任何内容)如果取消注释打印Filter Type名称的行->我得到了名称。 Please, help me to fix this issue. 请帮我解决此问题。

You should use f:selectItems instead, replace 您应该使用f:selectItems代替

<ui:repeat var="checkbox" value="#{filterTypeBean.listFilterTypes()}"
    varStatus="status">
    <!-- <h:outputText value="#{checkbox.filterTypeName}" /> -->
    <f:selectItem itemLabel="#{checkbox.filterTypeName}"
        itemValue="#{checkbox}" />
</ui:repeat>

by something like 通过类似

<f:selectItems var="checkbox" value="#{filterTypeBean.listFilterTypes()}" itemLabel="#{checkbox.filterTypeName}" itemValue="#{checkbox}" />

but I don't think your itemValue="#{checkbox}" will work since this your entire object containing description too. 但我认为您的itemValue="#{checkbox}"不起作用,因为这也可能itemValue="#{checkbox}"整个对象都包含说明。

More info : 更多信息 :

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM