Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top