org.apache.struts2.components
Class MergeIterator

java.lang.Object
  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.MergeIterator
All Implemented Interfaces:
Param.UnnamedParametric

public class MergeIterator
extends Component
implements Param.UnnamedParametric

Component for MergeIteratorTag, which job is to merge iterators and successive call to the merged iterator will cause each merge iterator to have a chance to expose its element, subsequently next call will allow the next iterator to expose its element. Once the last iterator is done exposing its element, the first iterator is allowed to do so again (unless it is exhausted of entries).

Internally the task are delegated to MergeIteratorFilter

Example if there are 3 lists being merged, each list have 3 entries, the following will be the logic.

  1. Display first element of the first list
  2. Display first element of the second list
  3. Display first element of the third list
  4. Display second element of the first list
  5. Display second element of the second list
  6. Display second element of the third list
  7. Display third element of the first list
  8. Display thrid element of the second list
  9. Display third element of the thrid list
public class MergeIteratorTagAction extends ActionSupport { private List myList1; private List myList2; private List myList3; public List getMyList1() { return myList1; } public List getMyList2() { return myList2; } public List getMyList3() { return 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"; } } <s:merge id="myMergedIterator1"> <s:param value="%{myList1}" /> <s:param value="%{myList2}" /> <s:param value="%{myList3}" /> </s:merge> <s:iterator value="%{#myMergedIterator1}"> <s:property /> </s:iterator> This wil generate "1aA2bB3cC".

See Also:
MergeIteratorFilter, MergeIteratorTag

Field Summary
private static Log _log
           
private  List _parameters
           
private  MergeIteratorFilter mergeIteratorFilter
           
 
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, id, parameters, stack
 
Constructor Summary
MergeIterator(ValueStack stack)
           
 
Method Summary
 void addParameter(Object value)
          Adds the given value as a parameter to the outer tag.
 boolean end(Writer writer, String body)
          Callback for the end tag of this component.
 void setId(String id)
           
 boolean start(Writer writer)
          Callback for the start tag of this component.
 
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, addParameter, altSyntax, copyParams, determineActionURL, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setActionMapper, toString, usesBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private static final Log _log

mergeIteratorFilter

private MergeIteratorFilter mergeIteratorFilter

_parameters

private List _parameters
Constructor Detail

MergeIterator

public MergeIterator(ValueStack stack)
Method Detail

start

public boolean start(Writer writer)
Description copied from class: Component
Callback for the start tag of this component. Should the body be evaluated?

Overrides:
start in class Component
Parameters:
writer - the output writer.
Returns:
true if the body should be evaluated

end

public boolean end(Writer writer,
                   String body)
Description copied from class: Component
Callback for the end tag of this component. Should the body be evaluated again?

NOTE: will pop component stack.

Overrides:
end in class Component
Parameters:
writer - the output writer.
body - the rendered body.
Returns:
true if the body should be evaluated again

setId

public void setId(String id)
Overrides:
setId in class Component

addParameter

public void addParameter(Object value)
Description copied from interface: Param.UnnamedParametric
Adds the given value as a parameter to the outer tag.

Specified by:
addParameter in interface Param.UnnamedParametric
Parameters:
value - the value


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.