Stripes:从另一个 ActionBean 调用一个 ActionBean 的方法

发布于 2024-12-15 04:02:07 字数 657 浏览 3 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断爱 2024-12-22 04:02:07

有几点:

如果您想在用户会话中存储数据,@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 通常不被鼓励
作者,Stripes 中将给予很少的津贴来容纳
会话范围 bean。

最后,实际上从一个操作 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

Since session scope ActionBeans are not generally encouraged by the
author, very few allowances will be made in Stripes to accommodate
session scope beans.

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文