Said another way, let's say I have a value stack that consists of a
model and an action as follows:
[ model, action ]
here's how the following ognl would resolve:
[0] - a CompoundRoot object that contains our stack, [model, action]
[1] - another CompoundRoot that contains only [action]
[0].toString() - calls toString() on the first object in the value stack (excluding the CompoundRoot) that supports the toString() method
[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
以上是webwork文檔中談到Value Stack部分.看了有些晦澀,我試驗了下,與大家分享.(沒看源代碼)
Action:

public?class?HomeAction?implements?Action?
{
????private?String?name=?"propertyOfAction";
????private?Person?person=null;
????private?Collection?collection?=?new?ArrayList();

????public?String?execute()?throws?Exception?
{
????????collection.add(new?Person("zkj"));
????????collection.add(new?Person("yql"));
????????collection.add(person);
????????return?SUCCESS;
????}

????public?String?getName()?
{
????????return?name;
????}

????public?Person?getPerson()?
{
????????return?person;
????}

????public?Collection?getCollection()?
{
????????return?collection;
????}

????public?void?setPerson(Person?person)?
{
????????this.person?=?person;
????}
}在jsp頁面中:
如果我們直接
<ww:property value="[0]"/>?? 輸出
com.founder.HomeAction@e3ffdf,com.opensymphony.xwork.DefaultTextProvider@d402dd]
<ww:property value="[1]"/>?? 輸出[com.opensymphony.xwork.DefaultTextProvider@d402dd]
一般我們在沒有循環(huán)的情況下不用[0]? [1] 可以直接訪問
<ww:property value="name"/>輸出? propertyOfAction
那么[0] [1] 有什么用呢,在循環(huán)中就體現(xiàn)出來了.
<ww:iterator?value="collection"?status="person">
????????????<ww:if?test="#person.first?==?true">?
????????????????[0]?:<ww:property?value="[0]"/></br>
????????????????[1]?:<ww:property?value="[1]"/></br>
????????????????[2]?:<ww:property?value="[2]"/></br>
????????????</ww:if>
</ww:iterator> [0] :[com.founder.Person@b3a5a0, com.founder.HomeAction@e3ffdf, com.opensymphony.xwork.DefaultTextProvider@d402dd]
[1] :[com.founder.HomeAction@e3ffdf, com.opensymphony.xwork.DefaultTextProvider@d402dd]
[2] :[com.opensymphony.xwork.DefaultTextProvider@d402dd]
輸出以上代碼,說明在一層循環(huán)中我們要訪問[1]表示action對象.和沒有循環(huán)的[0]對應.
總結(jié):
假如你用webworkNOUI標簽,對于Value Stack,一般你不要考慮[1] [0]之類的.記住一點
如果在循環(huán)中action的collection屬性時體內(nèi),用[1]可以訪問action對象和對應的屬性.
對于多層循環(huán)或復雜用法,我只能告訴你,你的設(shè)計有問題?重構(gòu)Model代碼吧.