Magazine
 
Struts2 Tags

Arrtibute</h3>
<s:generator
val=”%{‘JAVA,HTML,CSS,AJAX,JAVA
SCRIPT’}” count=”4" separator=”,”
id=”myAtt” />
<%
Iterator i = (Iterator)
pageContext.getAttribute(“myAtt”);
while(i.hasNext()) {
String s = (String) i.next(); %>
<%=s%> <br/>
<% }
%>
</body>
</html>

Output:

8. Subset Tag (Control Tags) Example
The subset tag is a generic tag that takes an iterator and outputs a subset of it. It delegates to org.apache.struts2.util.SubsetIteratorFilter internally to perform the subset functionality. Create a list in the action class and populate it with various items as shown in the
“SubsetTag” class.

 

SubsetTag.java

import
com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SubsetTag extends
ActionSupport {
private List list;
public String execute() throws Exception{
list = new ArrayList();
list.add(new Integer(100));
list.add(new Integer(200));
list.add(new Integer(300));
list.add(new Integer(150));
list.add(new Integer(400));
return SUCCESS;
}
public List getList(){
return list;
}
}

Now create a jsp page using <s:subset> and <s:iterator> tags as shown in the SubsetTag.jsp page. The subset tag takes an iterator and outputs a subset of it.

SubsetTag.jsp

<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Subset Tag Example</title>
</head>
<body>
<h2>Subset Tag Example</h2>
<s:subset source=”list”>
<s:iterator>
<s:property /><br>
</s:iterator>
</s:subset>
</body>
</html>


Output:

Dec 2007 | Java Jazz Up | 48
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF