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