This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • subset
Skip to end of metadata
Go to start of metadata

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

Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
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);
         }
     };
     }
 }
Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<!-- s: List basic -->
   <s:subset source="myList">
      <s:iterator>
         <s:property />
      </s:iterator>
   </s:subset>
Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<!-- B: List with count -->
   <s:subset source="myList" count="3">
      <s:iterator>
          <s:property />
      </s:iterator>
    </s:subset>
Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<!--  C: List with start -->
     <s:subset source="myList" count="13" start="3">
        <s:iterator>
          <s:property />
        </s:iterator>
     </s:subset>
Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<!--  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() %>
     <%  } %>
Error rendering macro 'code': Invalid value specified for parameter 'java.lang.NullPointerException'
<!--  D: List with Decider -->
    <s:subset source="myList" decider="myDecider">
           <s:iterator>
                <s:property />
           </s:iterator>
    </s:subset>
  • No labels

1 Comment

  1. If the "source" attribute is optional, what does it do if this attribute is not present?