FileDocCategorySizeDatePackage
Push.javaAPI DocExample5319Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

Push

public class Push extends Component

Push value on stack for simplified usage.

  • value* (Object) - value to be pushed into the top of the stack

Examples


<s:push value="user">
<s:propery value="firstName" />
<s:propery value="lastName" />
</s:push>

Pushed user into the stack, and hence property tag could access user's properties (firstName, lastName etc) since user is not at the top of the stack

<s:push value="myObject"> ----- (1)
<s:bean name="jp.SomeBean" id="myBean"/> ----- (2)
<s:param name="myParam" value="top"/> ----- (3)
</s:bean>
</s:push>


when in (1), myObject is at the top of the stack
when in (2), jp.SomeBean is in the top of stack, also in stack's context with key myBean
when in (3), top will get the jp.SomeBean instance


<s:push value="myObject"> ---(A)
<s:bean name="jp.SomeBean" id="myBean"/> ---(B)
<s:param name="myParam" value="top.mySomeOtherValue"/> ---(C)
</s:bean>
</s:push>


when in (A), myObject is at the top of the stack
when in (B), jp.SomeBean is at the top of the stack, also in context with key myBean
when in (C), top refers to jp.SomeBean instance. so top.mySomeOtherValue would invoke SomeBean's mySomeOtherValue() method


<s:push value="myObject"> ---- (i)
<s:bean name="jp.SomeBean" id="myBean"/> ---- (ii)
<s:param name="myParam" value="[1].top"/> -----(iii)
</s:bean>
</s:push>


when in (i), myObject is at the top of the stack
when in (ii), jp.SomeBean is at the top of the stack, followed by myObject
when in (iii), [1].top will returned top of the cut of stack starting from myObject, namely myObject itself

Fields Summary
protected String
value
protected boolean
pushed
Constructors Summary
public Push(com.opensymphony.xwork2.util.ValueStack stack)

        super(stack);
    
Methods Summary
public booleanend(java.io.Writer writer, java.lang.String body)

        ValueStack stack = getStack();

        if (pushed && (stack != null)) {
            stack.pop();
        }

        return super.end(writer, body);
    
public voidsetValue(java.lang.String value)

        this.value = value;
    
public booleanstart(java.io.Writer writer)

        boolean result = super.start(writer);

        ValueStack stack = getStack();

        if (stack != null) {
            stack.push(findValue(value, "value", "You must specify a value to push on the stack. Example: person"));
            pushed = true;
        } else {
            pushed = false; // need to ensure push is assigned, otherwise we may have a leftover value
        }

        return result;