Developing Web 2.0 applications
with JavaServerFaces
and Dreamweaver
>> Just Became Easier
Documentation
Search
  1. Introduction
  2. Getting Started
  3. Facelets Concepts
  4. Document Types
  5. Design View
  6. Code View Support
  7. Keyboard Shortcuts
  8. Tag Object Toolbars
  9. Property Inspectors
  10. Facelets Tag Reference
Facelets UI Tag Library
  ui:component
  ui:composition
  ui:debug
  ui:decorate
  ui:define
  ui:fragment
  ui:include
  ui:insert
  ui:param
  ui:remove
Selected ui:repeat
If you like this documentation, please take a look at my book:

10. Facelets UI Tag Reference

Documentation > Facelets > Facelets Tag Reference > Facelets UI Tag Library > ui:repeat

ui:repeat

The UI Repeat tag is used to iterate over a collection of objects exposed to the JSF page as a value-binding EL expression. It is intended as a replacement for the c:forEach tag from the JSTL Core tag library.

You can also use this tag with the "jsfc" feature in Facelets.

JSF Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<body>
<h:form>
	<ul>
		<ui:repeat value="#{productController.products}" var="product">
			<li><h:outputText value="#{product.name}" /></li>
		</ui:repeat>
	</ul>
</h:form>
</body>
</html>
This example was formatted by JSFToolbox for Dreamweaver.

Java Code

package com.mycompany.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import com.mycompany.model.Product;

@ManagedBean
@RequestScoped
public class ProductController {

	private List<Product> products;

	public List<Product> getProducts() {
		if (products == null) {
			products = new ArrayList<Product>();
			products.add(new Product("Tennis Racket"));
			products.add(new Product("Baseball Bat"));
			products.add(new Product("Hockey Stick"));
		}
		return products;
	}

}

Rendered Output

Rendered ui:repeat tag

HTML Output

<ul>
  <li>Tennis Racket</li>
  <li>Baseball Bat</li>
  <li>Hockey Stick</li>
</ul>

Tag Attributes

offset Text
Required
Read-write property setting the offset from the beginning of the collection from which to start the iteration. If not set, this offset is not considered and iteration will start at the beginning of the collection.
size Text
Required
Read-write property setting the size of the collection to iterate. If this value is less than the actual size of the collection, a FacesException must be thrown.
step Text
Required
Iteration will only process every step items of the collection, starting with the first one.
value Text
Required
The name of a collection of items that this tag iterates over. The collection may be a List, array, java. sql. ResultSet, or an individual java Object. If the collection is null, this tag does nothing.
var Text
Required
Name of the exported scoped variable for the current item of the iteration. This scoped variable has nested visibility. Its type depends on the object of the underlying collection
varStatus Text
Required
Name of the exported request scoped variable for the status of the iteration. Object is a POJO with the following read-only JavaBeans properties. This scoped variable has nested visibility. begin of type Integer end of type Integer index of type int step of type Integer even of type boolean odd of type boolean first of type boolean last of type boolean