Facelet repeat Tag
This tag is used to iterate over the list of items. The name of list of items is specified by the EL expression in the value attribute of this tag. This tag contains two attributes "value" "name". The literal name specified in the name attribute is used to iterate over the items. In this example, we have used a bean named "TableBean" and info name is given to be used further. For ex., info.id, info.name used in value attribute of inputText JSF tag where id and name are attributes specified in bean. so here all id and names will be displayed.
Code Description :
repeat.xhtml :
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <body> <center><h2>RoseIndia Facelet Tags Tutorial</h2></center> <h3>Welcome to the Facelet world..........</h3> <hr/> <ui:decorate template="/pages/repeat/repeattemplate.xhtml"> <ui:define name="face1"> <h3><h:outputText value="This is the list of ID and Names."/></h3> <ui:repeat value="#{TableBean.perInfoAll}" var="info"> <li> <h:inputText value="#{info.id}" /> <h:inputText value="#{info.name}" /> </li> </ui:repeat> </ui:define> </ui:decorate> </body> </html> |
repeattemplate.xhtml :
<!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:ui="http://java.sun.com/jsf/facelets"> <head> <title>facelet example </title> <link href="../../style/CSS.css" rel="stylesheet" type="text/css"/> </head> <body> <ui:insert name="face1"></ui:insert> </body> </html> |
TableBean.java :(Java Bean used for collection of items)
package roseindia; public class TableBean { private perInfo[] perInfoAll = new perInfo[]{ new perInfo(101, "CHANDAN", "9891444444", "aaa", 11111), new perInfo(102, "RAVI", "9911666666", "bbb" ,22222), new perInfo(103, "JOHN", "9313888888", "ccc", 33333), new perInfo(104, "ANDREW", "9911222222", "ddd" , 44444), new perInfo(105, "SYMONDS", "9313999999", "eee", 55555) }; public perInfo[] getperInfoAll() { return perInfoAll; } public class perInfo { int id; String name; String phone; String city; int pin; public perInfo(int id, String name, String phone, String city, int pin) { this.id = id; this.name = name; this.phone = phone; this.city = city; this.pin= pin; } public int getid() { return id; } public String getname() { return name; } public String getphone() { return phone; } public String getcity() { return city; } public int getpin() { return pin; } } } |
Rendered Output :
Html Source Code :
<!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"> <body> <center><h2>RoseIndia Facelet Tags Tutorial</h2></center> <h3>Welcome to the Facelet world..........</h3> <hr /><!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"> <head> <title>facelet example </title> <link href="../../style/CSS.css" rel="stylesheet" type="text/css" /> </head> <body> <h3>This is the list of ID and Names.</h3> <li> <input type="text" name="_id7:0:_id9" value="101" /> <input type="text" name="_id7:0:_id10" value="CHANDAN" /> </li> <li> <input type="text" name="_id7:1:_id9" value="102" /> <input type="text" name="_id7:1:_id10" value="RAVI" /> </li> <li> <input type="text" name="_id7:2:_id9" value="103" /> <input type="text" name="_id7:2:_id10" value="JOHN" /> </li> <li> <input type="text" name="_id7:3:_id9" value="104" /> <input type="text" name="_id7:3:_id10" value="ANDREW" /> </li> <li> <input type="text" name="_id7:4:_id9" value="105" /> <input type="text" name="_id7:4:_id10" value="SYMONDS" /> </li> </body> </html> </body> </html> |
This tag contains two attributes :
value : This attribute specifies the list of items whose items are to be
iterated. This is the EL expression.
var : This attribute is used to give a name using that the iteration is
done.