Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > subset
Added by Jay Bose, last edited by Don Brown on Jan 06, 2007  (view change)

Description

NOTE: JSP-TAG

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.

Parameters

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
id false false String Deprecated. Use 'var' instead
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);
         }
     };
     }
 }
<!-- s: List basic -->
   <s:subset source="myList">
      <s:iterator>
         <s:property />
      </s:iterator>
   </s:subset>
<!-- B: List with count -->
   <s:subset source="myList" count="3">
      <s:iterator>
          <s:property />
      </s:iterator>
    </s:subset>
<!--  C: List with start -->
     <s:subset source="myList" count="13" start="3">
        <s:iterator>
          <s:property />
        </s:iterator>
     </s:subset>
<!--  D: List with var -->
     <s:subset var="mySubset" source="myList" count="13" start="3" />
     <%
         Iterator i = (Iterator) pageContext.getAttribute("mySubset");
         while(i.hasNext()) {
     %>
     <%=i.next() %>
     <%  } %>
<!--  D: List with Decider -->
    <s:subset source="myList" decider="myDecider">
           <s:iterator>
                <s:property />
           </s:iterator>
    </s:subset>