FileDocCategorySizeDatePackage
AppendIterator.javaAPI DocExample5991Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

AppendIterator

public class AppendIterator extends Component implements org.apache.struts2.components.Param.UnnamedParametric

Component for AppendIteratorTag, which jobs is to append iterators to form an appended iterator whereby entries goes from one iterator to another after each respective iterator is exhausted of entries.

For example, if there are 3 iterator appended (each iterator has 3 entries), the following will be how the appended iterator entries will be arranged:

  1. First Entry of the First Iterator
  2. Second Entry of the First Iterator
  3. Third Entry of the First Iterator
  4. First Entry of the Second Iterator
  5. Second Entry of the Second Iterator
  6. Third Entry of the Second Iterator
  7. First Entry of the Third Iterator
  8. Second Entry of the Third Iterator
  9. Third Entry of the Third ITerator
  • id (String) - the id of which if supplied will have the resultant appended iterator stored under in the stack's context
public class AppendIteratorTagAction extends ActionSupport { private List myList1; private List myList2; private List myList3; public String execute() throws Exception { myList1 = new ArrayList(); myList1.add("1"); myList1.add("2"); myList1.add("3"); myList2 = new ArrayList(); myList2.add("a"); myList2.add("b"); myList2.add("c"); myList3 = new ArrayList(); myList3.add("A"); myList3.add("B"); myList3.add("C"); return "done"; } public List getMyList1() { return myList1; } public List getMyList2() { return myList2; } public List getMyList3() { return myList3; } } <s:append id="myAppendIterator"> <s:param value="%{myList1}" /> <s:param value="%{myList2}" /> <s:param value="%{myList3}" /> </s:append> <s:iterator value="%{#myAppendIterator}"> <s:property /> </s:iterator>
see
org.apache.struts2.util.AppendIteratorFilter
see
org.apache.struts2.views.jsp.iterator.AppendIteratorTag

Fields Summary
private static final Log
_log
private org.apache.struts2.util.AppendIteratorFilter
appendIteratorFilter
private List
_parameters
Constructors Summary
public AppendIterator(com.opensymphony.xwork2.util.ValueStack stack)


       
        super(stack);
    
Methods Summary
public voidaddParameter(java.lang.Object value)

        _parameters.add(value);
    
public booleanend(java.io.Writer writer, java.lang.String body)


        for (Iterator paramEntries = _parameters.iterator(); paramEntries.hasNext(); ) {

            Object iteratorEntryObj = paramEntries.next();
            if (! MakeIterator.isIterable(iteratorEntryObj)) {
                _log.warn("param with value resolved as "+iteratorEntryObj+" cannot be make as iterator, it will be ignored and hence will not appear in the merged iterator");
                continue;
            }
            appendIteratorFilter.setSource(MakeIterator.convert(iteratorEntryObj));
        }

        appendIteratorFilter.execute();

        if (getId() != null && getId().length() > 0) {
            getStack().getContext().put(getId(), appendIteratorFilter);
        }

        appendIteratorFilter = null;

        return super.end(writer, body);
    
public voidsetId(java.lang.String id)

        super.setId(id);
    
public booleanstart(java.io.Writer writer)

        _parameters = new ArrayList();
        appendIteratorFilter = new AppendIteratorFilter();

        return super.start(writer);