1

I'm migrating an existing Struts1 application to Struts2. I've kept the Actions and ActionForms classes hierarchy the same.

The Struts2 actions SuperAction extends from ActionSupport and has a ModerlDriven member variable SuperForm while SubAction extends from SuperAction and has a ModelDriven member variable SubForm.

Of course, SubForm is a subclass of SuperForm. Both SubAction and SuperAction have some action methods.

SubAction constructor is like:

    public SubAction() {
      subForm = new SubForm();
      this.superForm(this.subForm);
    }

Now, I've a scenario where I'm calling a SuperAction method from the mapping of SubAction like:

    <package name="sub-pkg" namespace="/subns" extends="struts-default" strict-method-invocation="true">
        <action name="subAction_*" method="{1}" class="com.company.SubAction">
          <result name="showArchived" type="chain">subAction_list</result>
          <result name="list">/jsps/list_logs.jsp</result>
          <allowed-methods>list, showArchived</allowed-methods>
        </action>
    </package>

The SuperAction.showArchived() action method sets values in its member variable superForm.setLogMode() and returns String showArchived, which, as can be seen from the mapping, is chaining with the SubAction.list() action method.

This method makes use of SuperForm attribute logMode from its member variable subForm and returns String list to display the list_logs.jsp.

The action chaining is working but it's not passing SuperForm attribute value logMode, in this case of SuperAction method chain to SubAction method.

Any suggestions?

Update:

As a matter of fact, I found a general problem which is not specific to SuperClass/SubClass actions. It is occurring in general, in that using type="chain" is not working for model object in ModelDriven actions.

Therefore the chain doesn't re-populate the model properties at the end of the chain to the second action.

Any suggestions would be appreciated.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Shah-G
  • 652
  • 1
  • 8
  • 22
  • 1
    Chaining is a whole ball of wax that's generally best to avoid (IMO). It's great for simple stuff, but leads to all sorts of issues when complexity is introduced. That said: it's not clear to me what your issue is--you're saying there's a filled property in `SuperForm` that isn't reflected in `SubForm`? If that's the case we'll probably need some more info around the form classes. – Dave Newton Feb 01 '18 at 16:23
  • See suggestions below. – Roman C Feb 05 '18 at 22:20
  • @DaveNewton, `SubForm` is a subclass of `SuperForm`. What more do you need to know? – Shah-G Feb 06 '18 at 11:55

1 Answers1

0

TL;DR

The chain result creates a new valueStack with the same action bean and populates it from the old stack.

When the chained action is invoked it has a params interceptor on the stack.

When params interceptor is invoked it populates the action bean from ActionContext parameters.


What you have to the attribute populates by the params interceptor. If you are missing some attribute check request parameters and you have getters setters to the attribute property.

The action chaining is working but it's not passing SuperForm attribute value


Some properties to be accessible from the ModelDriven root should use this solution.

The modelDriven interceptor pushes the model on top of the valueStack, so it is easy to use it in JSP. The action object is below the model. So, it could be referenced directly using [1] prefix. See OGNL basics.

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