Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » views » jsp » iterator » [javadoc | source]
org.apache.struts2.views.jsp.iterator
public class: IteratorGeneratorTag [javadoc | source]
java.lang.Object
   javax.servlet.jsp.tagext.TagSupport
      javax.servlet.jsp.tagext.BodyTagSupport
         org.apache.struts2.views.jsp.StrutsBodyTagSupport
            org.apache.struts2.views.jsp.iterator.IteratorGeneratorTag

All Implemented Interfaces:
    BodyTag, IterationTag, Serializable

NOTE: JSP-TAG

Generate an iterator based on the val attribute supplied.

NOTE: The generated iterator will ALWAYS be pushed into the top of the stack, and poped at the end of the tag. Example One:
Generate a simple iterator
<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}">
 <s:iterator>
     <s:property /><br/>
 </s:iterator>
</s:generator>
This generates an iterator and print it out using the iterator tag. Example Two:
Generate an iterator with count attribute
<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="3">
 <s:iterator>
     <s:property /><br/>
 </s:iterator>
</s:generator>
This generates an iterator, but only 3 entries will be available in the iterator generated, namely aaa, bbb and ccc respectively because count attribute is set to 3 Example Three:
Generate an iterator with var attribute
<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" count="4" separator="," var="myAtt" />
<%
 Iterator i = (Iterator) pageContext.getAttribute("myAtt");
 while(i.hasNext()) {
     String s = (String) i.next(); %>
     <%=s%> <br/>
<%    }
%>
This generates an iterator and put it in the PageContext under the key as specified by the var attribute. Example Four:
Generate an iterator with comparator attribute
<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}" converter="%{myConverter}">
 <s:iterator>
     <s:property /><br/>
 </s:iterator>
</s:generator>


public class GeneratorTagAction extends ActionSupport {

  ....

  public Converter getMyConverter() {
     return new Converter() {
         public Object convert(String value) throws Exception {
             return "converter-"+value;
         }
     };
  }

  ...

}
This will generate an iterator with each entries decided by the converter supplied. With this converter, it simply add "converter-" to each entries.
Field Summary
public static final  String DEFAULT_SEPARATOR     
 String countAttr     
 String separatorAttr     
 String valueAttr     
 String converterAttr     
 String var     
 IteratorGenerator iteratorGenerator     
Fields inherited from javax.servlet.jsp.tagext.BodyTagSupport:
bodyContent
Fields inherited from javax.servlet.jsp.tagext.TagSupport:
id,  pageContext,  class$javax$servlet$jsp$tagext$Tag
Method from org.apache.struts2.views.jsp.iterator.IteratorGeneratorTag Summary:
doEndTag,   doStartTag,   setConverter,   setCount,   setId,   setSeparator,   setVal,   setVar
Methods from org.apache.struts2.views.jsp.StrutsBodyTagSupport:
findString,   findValue,   findValue,   getBody,   getStack,   toString
Methods from javax.servlet.jsp.tagext.BodyTagSupport:
doAfterBody,   doEndTag,   doInitBody,   doStartTag,   getBodyContent,   getPreviousOut,   release,   setBodyContent
Methods from javax.servlet.jsp.tagext.TagSupport:
class$,   doAfterBody,   doEndTag,   doStartTag,   findAncestorWithClass,   getId,   getParent,   getValue,   getValues,   release,   removeValue,   setId,   setPageContext,   setParent,   setValue
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts2.views.jsp.iterator.IteratorGeneratorTag Detail:
 public int doEndTag() throws JspException 
 public int doStartTag() throws JspException 
 public  void setConverter(String aConverter) 
 public  void setCount(String count) 
 public  void setId(String string) 
 public  void setSeparator(String separator) 
 public  void setVal(String val) 
 public  void setVar(String var)