Action chaining not forwarding ModelDriven model properties

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Action chaining not forwarding ModelDriven model properties

shahzad.ismail@gmail.com
Hi,
I'm migrating an app from Struts 1 to Struts 2 (Tomcat v8 and Struts 2.5.14.1). There is a scenario in which mapping goes like:
jsp1 --> action1 --> action2 --> action3 --> jsp2

So it must be type="chain" for action1 --> action2 and action2 --> action3 as I need to pass ModelDriven model as well as some action member variables, some of them are non-strings. All 3 actions are chaining to different methods of the same action class.  
The **problem** is that action1 --> action2 is passing action variables but not passing any properties of model even though action2 --> action3 is passing all the action variables as well as model properties.  
I'm only using defaultStack of interceptor.  
My interceptors are defined as:  

    <interceptors>
          <interceptor-stack name="adssStack">
                <interceptor-ref name="logger" />
                                <interceptor-ref name="defaultStack">
              <param name="exception.logEnabled">true</param>
              <param name="exception.logLevel">DEBUG</param>
              <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
            </interceptor-ref>
             </interceptor-stack>
                </interceptors>
                <default-interceptor-ref name="adssStack" />


And I'm using them as:  

    <action name="kmList_*" method="{1}" class="com.pkg.MyAction">
         <interceptor-ref name="adssStack">
            <param name="validation.excludeMethods">*</param>
            <param name="validation.includeMethods">insert</param>
            <param name="workflow.excludeMethods">*</param>
            <param name="workflow.includeMethods">insert</param>
        </interceptor-ref>
        <result name="searchKM" type="chain">kmList_actionmethod2</result>
        <result name="moveToList" type="chain">kmList_actionmethod3</result>
        <allowed-methods>
            actionmethod1, actionmethod2, actionmethod3
        </allowed-methods>
    </action>

I've debugged it a bit and able to figure out that, initially, at the start of action1, request.getParamater("modelprop") is null then I set modelprop in the action1 method which makes mymodel.modelprop == "something" and request.getAttribute("modelprop") == "something" but the request.getParameter("modelprop") remains null by the end of action1 method. So when it chains to action2 method, it simply rewrites request.getParameter("modelprop") value, which is *null*, back to both, request.getAttribute("modelprop") and mymodel.modelprop. Am I messing up with some interceptor configuration?
I've tried it with type="redirectAction" and the problem of not passing mymodel.modelprop from action1 to action2 remains.
Any suggestions would be appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Action chaining not forwarding ModelDriven model properties

Lukasz Lenart
Can you share a source code of your actions?

2018-02-28 13:17 GMT+01:00 [hidden email] <[hidden email]>:

> Hi,
> I'm migrating an app from Struts 1 to Struts 2 (Tomcat v8 and Struts 2.5.14.1). There is a scenario in which mapping goes like:
> jsp1 --> action1 --> action2 --> action3 --> jsp2
>
> So it must be type="chain" for action1 --> action2 and action2 --> action3 as I need to pass ModelDriven model as well as some action member variables, some of them are non-strings. All 3 actions are chaining to different methods of the same action class.
> The **problem** is that action1 --> action2 is passing action variables but not passing any properties of model even though action2 --> action3 is passing all the action variables as well as model properties.
> I'm only using defaultStack of interceptor.
> My interceptors are defined as:
>
>     <interceptors>
>                         <interceptor-stack name="adssStack">
>                         <interceptor-ref name="logger" />
>                                 <interceptor-ref name="defaultStack">
>                                 <param name="exception.logEnabled">true</param>
>                                 <param name="exception.logLevel">DEBUG</param>
>                                 <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
>                                 </interceptor-ref>
>                     </interceptor-stack>
>                 </interceptors>
>                 <default-interceptor-ref name="adssStack" />
>
>
> And I'm using them as:
>
>     <action name="kmList_*" method="{1}" class="com.pkg.MyAction">
>          <interceptor-ref name="adssStack">
>             <param name="validation.excludeMethods">*</param>
>             <param name="validation.includeMethods">insert</param>
>             <param name="workflow.excludeMethods">*</param>
>             <param name="workflow.includeMethods">insert</param>
>         </interceptor-ref>
>         <result name="searchKM" type="chain">kmList_actionmethod2</result>
>         <result name="moveToList" type="chain">kmList_actionmethod3</result>
>         <allowed-methods>
>             actionmethod1, actionmethod2, actionmethod3
>         </allowed-methods>
>     </action>
>
> I've debugged it a bit and able to figure out that, initially, at the start of action1, request.getParamater("modelprop") is null then I set modelprop in the action1 method which makes mymodel.modelprop == "something" and request.getAttribute("modelprop") == "something" but the request.getParameter("modelprop") remains null by the end of action1 method. So when it chains to action2 method, it simply rewrites request.getParameter("modelprop") value, which is *null*, back to both, request.getAttribute("modelprop") and mymodel.modelprop. Am I messing up with some interceptor configuration?
> I've tried it with type="redirectAction" and the problem of not passing mymodel.modelprop from action1 to action2 remains.
> Any suggestions would be appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Action chaining not forwarding ModelDriven model properties

Yasser Zamani-2
In reply to this post by shahzad.ismail@gmail.com


On 2/28/2018 3:47 PM, shahzad.ismail@ wrote:
> I've debugged it a bit and able to figure out that, initially, at the start of action1, request.getParamater("modelprop") is null then I set modelprop in the action1 method which makes mymodel.modelprop == "something" and request.getAttribute("modelprop") == "something" but the request.getParameter("modelprop") remains null by the end of action1 method. So when it chains to action2 method, it simply rewrites request.getParameter("modelprop") value, which is *null*, back to both, request.getAttribute("modelprop") and mymodel.modelprop. Am I messing up with some interceptor configuration?
> I've tried it with type="redirectAction" and the problem of not passing mymodel.modelprop from action1 to action2 remains.
> Any suggestions would be appreciated.

AFAIR the chain result doesn't set destination action props from
request, but in your case, it calls action1.getModel() and gets the
object then calls action2.setModel(the object).

Could you try these and see what happens:

1. Via your browser, browse action2 directly (instead of action1).
2. Try different configs like action2->action3->action1, or
action3->action1->action2, or action2->action1->action3, or
action3->action2->action1.

Regards.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]