Iterate in JSF, providing simple HTML <div> elements using for each loop

I am using JSF 2 with Facelets. I have a managed bean that has a property related to List<Employee> . Now I have a <h:dataTable> that can create a table from this collection in a simple way.

I need something else, I need to create a <div> element with <img> for each element in this collection. How can I achieve this in JSF 2 with Facelets?

+6
collections foreach facelets jsf jsf-2
source share
1 answer

You can use <ui:repeat> to iterate over the collection while controlling the markup. For example.

 private List<Employee> employees; @EJB private EmployeeService employeeService; @PostConstruct public void init() { employees = employeeService.list(); } public List<Employee> getEmployees() { return employees; } 
 <ui:repeat value="#{bean.employees}" var="employee"> <div><img src="#{employee.image}" /></div> </ui:repeat> 
+10
source share

All Articles