struts2操作类层次结构从SuperAction链接到SubAction方法 [英] struts2 action classes hierarchy chaining from SuperAction to SubAction methods

查看:676
本文介绍了struts2操作类层次结构从SuperAction链接到SubAction方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有的struts1应用程序迁移到struts2。我保持Actions和ActionForms类层次结构相同。 struts2操作 SuperAction ActionSupport 扩展而且有一个 ModerlDriven 成员变量 SuperForm ,而 SubAction SuperAction 扩展而且有一个 ModelDriven 成员变量 SubForm [更新] 当然, SubForm SuperForm的子类 SubAction SuperAction 都有一些操作方法。

SubAction构造函数如下:

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. [Update] Ofcourse, 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);
}

现在,我有一个场景,我正在调用SuperAction方法SubAction的映射如:

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>

SuperAction.showArchived()操作方法在其成员变量 superForm.setLogMode()中设置值,并返回字符串showArchived;从映射中可以看出,它与 SubAction.list()动作方法相关联。此方法使用 SuperForm 属性, logMode ,从其成员变量 subForm ,并返回字符串list以显示 list_logs.jsp

动作链接正在运行,但它没有传递SuperForm属性值, logMode ,在这种情况下SuperAction方法链到SubAction方法。

任何建议?

[更新]

事实上,我发现了一个非特定于SuperClass / SubClass操作的一般问题。它通常发生在使用 type =chain NOT 为ModelDriven动作中的模型对象工作。因此,链不会在action2的链末尾重新填充模型属性。
任何建议都将受到赞赏。

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 chain for action2. Any suggestions would be appreciated.

推荐答案

TL; DR


链结果创建一个具有相同操作bean
的新值堆栈,并从旧堆栈中填充它。

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

当调用链式动作时,它在
堆栈上有一个params拦截器。

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

当调用params拦截器时,它会填充动作来自
动作上下文参数的bean。

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






你对属性有什么填充 param 拦截器。如果您缺少某些属性检查请求参数,并且您具有属性属性的getter setter。


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


操作链接正在运行,但它没有通过SuperForm属性值

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






可从模型驱动的根访问的某些属性应使用
解决方案。


modelDriven 拦截器将模型推到值
之上堆栈,所以很容易在JSP中使用它。 action对象位于
模型下方。因此,可以使用 [1] 前缀直接引用它。请参阅
OGNL基础知识

The modelDriven interceptor pushes the model on top of the value stack, 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.

这篇关于struts2操作类层次结构从SuperAction链接到SubAction方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆