Scope attribute migration from Struts1 to Struts2

2.1k views Asked by At

I am migrating an application from Struts1 to Struts2. I could migrate everything except the scope attribute from the below action tag of the Struts1 configuration file (struts-config.xml).

Struts1 configuration:

<action path="/DomainAndIPBlocking" 
        type="com.tarangtech.da.struts.action.DomainBlockedListAction" 
        name="DomainBlockForm" 
        scope="session" 
        input="/DomainAndIPBlocking.do"
        validate="false">
    <forward name="success" path="/jsp/SystemAdminConsol/DomainBlocking.jsp"/>
</action>

Migrated Struts2 configuration:

<action name="DomainAndIPBlocking" 
        class="com.tarangtech.da.struts.action.DomainBlockedListAction" 
        method="execute">
    <result name="success">/jsp/SystemAdminConsol/DomainBlocking.jsp</result>
</action>

The form DomainBlockForm has been integrated by extending the action class DomainBlockedListAction like this:

public class DomainBlockedListAction extends DomainBlockForm

It is required for me to carry forward the form values across the application. But these values are available in request/page scope only. So, I should have an alternative for scope="session" from Struts1 to Struts2, so that I can carry forward all the attributes across the application.

1

There are 1 answers

2
Michael Peacock On BEST ANSWER

From the Struts 1 DTD in the Action Element definition:

    scope        The context ("request" or "session") that is used to
                 access our ActionForm bean, if any.  Optional if "name" is
                 specified, else not valid. [session]

In Struts 2, there are no Action Form beans, and Actions themselves default to request context. @meskobalazs is correct above, this can be overridden with the scope interceptor if you need session-scoped actions in Struts 2.