Stripes:从另一个 ActionBean 调用一个 ActionBean 的方法
我是 Stripes 框架的新手,需要一些帮助。
我想从另一个 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
}
...
}
从 TestActionBean 调用 SessionActionBean 的 setUsername?如果 SessionActionBean 不在会话范围内呢?
提前致谢
I am new on using the Stripes framework and I need some help.
I want to call a method of an ActionBean from another ActionBean.
For example, I have two ActionBean:
@SessionScope
public class SessionActionBean extends AbstractActionBean{
private String property;
public void setUsername(String username) {
this.username = username;
}
}
And
public class TestActionBean extends AbstractActionBean {
...
public Resolution submitTest() {
//TODO Call setUsername is SessionActionBean
}
...
}
How do I call the setUsername of the SessionActionBean from TestActionBean? And if the SessionActionBean was not session scoped?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几点:
如果您想在用户会话中存储数据,
@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
最后,实际上从一个操作 bean 到另一个操作 bean 调用方法就像实例化 bean 并调用方法一样简单。这有点奇怪和倒退,实例化的 bean 不会继承 Stripes 上下文的东西,但你可以这样做。
如果您希望一个 @Resolution 调用另一个 @Resolution,您也可以这样做:
ForwardResolution(Class; beanType)
。A few things:
If you want to store data in a user's session,
@SessionScope
isn't really what you want. You'd be better off extending ActionBeanContext and writing some getters and setters that store in context. See http://www.stripesframework.org/display/stripes/State+Management for more details.If you really really want to use @SessionScope, make sure you read the caveat in the javadoc and make sure that's really what you need.
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/action/SessionScope.html
Finally, actually invoking methods from one action bean to the other is as simple as instantiating the bean and calling the method. It's kind of weird and backwards and the instantiated bean won't inherit Stripes context stuff, but you can do it.
If you'd rather have one @Resolution call another @Resolution, you can do that too:
ForwardResolution(Class<? extends ActionBean> beanType)
.