Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

As Matt Ho explained on the mailing list:

Wiki Markup A value stack is essentially a List. Calling \ [1] on the stack,
returns a substack beginning with the element at index 1. It's only
when you call methods on the stack that your actual objects will be
called.

Said another way, let's say I have a value stack that consists of a
model and an action as follows:

Wiki Markup \ [ model, action ]

here's how the following ognl would resolve:

Wiki Markup \ [0] - a CompoundRoot object that contains our stack, \ [OS:model, action]unmigrated-wiki-markup

\ [1] - another CompoundRoot that contains only \ [OS:action]

Wiki Markup \ [0].toString() - calls toString() on the first object in the value
stack (excluding the CompoundRoot) that supports the toString() method Wiki Markup

\ [1].foo - call getFoo() on the first object in the value stack
starting from \ [OS:action] and excluding the CompoundRoot that supports a
getFoo() method

I hope this doesn't sound too confusing :\

If you're using Velocity, this can most easily be written as:

Wiki Markup $stack.findValue("\[0]").peek()

Unfortunately, <ww:property value="[0].peek()"/> won't work as this
would translate into "starting at the top of the value stack (and
excluding the CompoundRoot), find the first object that has a method
called peek()"

...

Code Block
public class CompoundRoot extends ArrayList {
    //~ Constructors ///////////////////////////////////////////////////////////

    public CompoundRoot() {
    }

    public CompoundRoot(List list) {
        super(list);
    }

    //~ Methods ////////////////////////////////////////////////////////////////

    public CompoundRoot cutStack(int index) {
        return new CompoundRoot(subList(index, size()));
    }

    public Object peek() {
        return get(0);
    }

    public Object pop() {
        return remove(0);
    }

    public void push(Object o) {
        add(0, o);
    }
}

What's on the stack?

NOTE: When rendering Freemarker / Velocity templates or result,
WebWork2 contains the following items by default in the ValueStack:

  • req - the current HttpServletRequest
  • res - the current HttpServletResponse
  • stack - the current OgnlValueStack
  • ognl - an instance of OgnlTool
  • ui - a (now deprecated) instance of a ui tag renderer

@See com.opensymphony.webwork.views.util.ContextUtil