Edit on GitHub << back to Tag Reference

# subset

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

## Description

A 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.

Takes an iterator and outputs a subset of it.

## Attributes

#### Dynamic Attributes Allowed: false
#### Name | #### Required | #### Default | #### Evaluated | #### Type | #### Description
--- | --- | --- | --- | --- | ---
count | false |  | false | Integer | Indicate the number of entries to be in the resulting subset iterator
decider | false |  | false | org.apache.struts2.util.SubsetIteratorFilter.Decider | Extension to plug-in a decider to determine if that particular entry is to be included in the resulting subset iterator
performClearTagStateForTagPoolingServers | false | false | false | Boolean | Whether to clear all tag state during doEndTag() processing
source | false |  | false | String | Indicate the source of which the resulting subset iterator is to be derived base on
start | false |  | false | Integer | Indicate the starting index (eg. first entry is 0) of entries in the source to be available as the first entry in the resulting subset iterator
var | false |  | false | String | The name to store the resultant iterator into page context, if such name is supplied

## Examples

    public class MySubsetTagAction extends ActionSupport {
         public String execute() throws Exception {
            l = new ArrayList();
            l.add(new Integer(1));
            l.add(new Integer(2));
            l.add(new Integer(3));
            l.add(new Integer(4));
            l.add(new Integer(5));
            return "done";
         }

         public Integer[] getMyArray() {
            return a;
         }

         public List getMyList() {
            return l;
          }

         public Decider getMyDecider() {
             return new Decider() {
                 public boolean decide(Object element) throws Exception {
                     int i = ((Integer)element).intValue();
                     return (((i % 2) == 0)?true:false);
                 }
             };
         }
    }

Basic example

    <s:subset source="myList">
       <s:iterator>
          <s:property />
       </s:iterator>
    </s:subset>

List with count

    <s:subset source="myList" count="3">
       <s:iterator>
           <s:property />
       </s:iterator>
    </s:subset>

List with start

    <s:subset source="myList" count="13" start="3">
       <s:iterator>
         <s:property />
       </s:iterator>
    </s:subset>

List with var

    <s:subset var="mySubset" source="myList" count="13" start="3" />
    <%
        Iterator i = (Iterator) pageContext.getAttribute("mySubset");
        while(i.hasNext()) {
    %>
    <%=i.next() %>
    <%  } %>

List with Decider

    <s:subset source="myList" decider="myDecider">
           <s:iterator>
                <s:property />
           </s:iterator>
    </s:subset>

Follow @x