2011-11-11 24 views
1

我是使用Stripes框架的新手,我需要一些幫助。Stripes:從另一個ActionBean調用ActionBean的方法

我想從另一個ActionBean調用一個ActionBean的方法。

例如,我有兩個的ActionBean:

@SessionScope 
public class SessionActionBean extends AbstractActionBean{ 

    private String property;   

    public void setUsername(String username) { 
     this.username = username; 
    } 
} 

而且

public class TestActionBean extends AbstractActionBean { 

    ... 

    public Resolution submitTest() {   

     //TODO Call setUsername is SessionActionBean 
    } 

    ... 
} 

如何調用SessionActionBean從TestActionBean的通過setUsername?如果SessionActionBean不是會話作用域?

在此先感謝

回答

3

有幾件事情:

如果你想將數據存儲在用戶的會話,@SessionScope是不是真的你想要什麼。你最好是擴展ActionBeanContext並編寫一些存儲在上下文中的getter和setter。有關更多詳細信息,請參見http://www.stripesframework.org/display/stripes/State+Management

如果你真的想要使用@SessionScope,請確保你閱讀了javadoc中的警告,並確保它真的是你需要的。

http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/action/SessionScope.html

由於會話範圍ActionBeans一般不被 作者鼓勵,很少津貼將被條紋,以適應 會話範圍豆。

最後,實際從一個動作bean調用方法到另一個動作bean就像實例化bean並調用方法一樣簡單。這有點古怪,而且實例化的bean不會繼承Stripes上下文,但是你可以做到。

如果您希望有一個@Resolution調用另一個@Resolution,您也可以這樣做:ForwardResolution(Class<? extends ActionBean> beanType)

+0

帶狀態管理的更新鏈接:https://stripesframework.atlassian.net/wiki/plugins/servlet/mobile?contentId=492007#content/view/492007 – RobertG