Magazine
 
Struts2 Tags

9. Subset Tag (Control Tags) Example
Using Count

In this section, we are going to describe the subset tag using the count parameter. The count parameter indicates the number of entries to be set in the resulting subset
iterator. Create a list in the action class and populate it with various items as shown in the “SubsetTag” class.

SubsetTag.java

package net.javajazzup;
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. The
parameter count is of integer type and it sets the number of entries to be kept in the resulting subset iterator.

SubsetTagCount.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” count=”3">
<s:iterator>
<s:property /><br>
</s:iterator>
</s:subset>
</body>
</html>

Output:

Output displays only three items because count=3.

10. Subset Tag (Control Tags) Example
Using Start

In this section, we are going to describe the subset tag using the start parameter. The start parameter is of integer type. It indicates the starting index (eg. first entry is 0) of entries in the source (needed to make
available as the first entry in the resulting subset iterator). Create a list in the action class and populate it with various items as shown in “SubsetTag” class.


Dec 2007 | Java Jazz Up | 49
 
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