2

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176

1 Answers1

1

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.

Michael Peacock
  • 2,011
  • 1
  • 11
  • 14
  • @meskobalazs Thanks for your quick answer. If I need to add all the attributes of action class in session scope, it is required to write all the fields in this filter. It will be good if you suggest any simple way to specify all the fields in this filter. means currently I have to specify like this field1, filed2, filed3,... – Shahul Hameed Sheik Abdullah Jun 11 '15 at 06:13
  • Not knowing your requirements, I would caution against assuming that all parameters need to be in session scope. Even so, you could add the params to the scope interceptor as shown above. Alternatively, implement the [SessionAware interface](https://struts.apache.org/maven/struts2-core/apidocs/org/apache/struts2/interceptor/SessionAware.html) in your action to provide programmatic access to the session, keeping in mind some [suggested best practices](https://struts.apache.org/docs/http-session.html). Good luck! – Michael Peacock Jun 12 '15 at 13:50