2

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:

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. Please, help me to fix this issue.

1
  • 1
    There is f:selectItems for that purpose. Apr 15, 2014 at 19:08

1 Answer 1

4

You should use f:selectItems instead, replace

<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.

More info :

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.