简体   繁体   English

Struts 2.3 Store Interceptor:如何将ActionErrors从Interceptor传递给Action?

[英]Struts 2.3 Store Interceptor : How to pass ActionErrors from Interceptor to Action?

I have been reading about the StoreInterceptor in the Struts 2 docs, and it talks about how to stick the StoreInterceptor in your Action definition in your struts-config.xml , and it just works.我一直在 Struts 2 文档中阅读有关StoreInterceptor的内容,它讨论了如何将 StoreInterceptor 粘贴到您的struts-config.xml中的 Action 定义中,并且它可以正常工作。 But that is if you are creating and adding the ActionErrors from within the Action.但那是如果您从 Action 中创建和添加ActionErrors

My problem is that I am doing a Login using a LoginInterceptor which, if the Login fails, adds an ActionError like so:我的问题是我正在使用LoginInterceptor进行登录,如果登录失败,则会添加一个ActionError如下所示:

((ActionSupport) invocation.getAction()).addActionError("Login failed");

It's added just fine, but when I get to the LoginAction, which is invoked after the LoginInterceptor , ValidationAwareSupport.actionErrors is null .它添加得很好,但是当我到达在 LoginInterceptor之后调用的LoginInterceptorValidationAwareSupport.actionErrorsnull

I thought that by adding the StoreInterceptor like this, it would store the ActionErrors , either in request or session (using the operationMode "store" or "retreive" parameter):我认为通过像这样添加StoreInterceptor ,它会在请求或会话中存储ActionErrors (使用operationMode "store""retreive"参数):

<action name="login" class="...LoginFormAction" >
 <interceptor-ref name="store">
  <param name="operationMode">store</param>
 </interceptor-ref>
 <interceptor-ref name="defaultStack" />
  <result name="input" type="tiles">adminLogin</result>
  <result name="success" type="tiles">adminLogin</result>
</action>

But it's not working.但它不起作用。 I've also tried adding the StoreInterceptor directly to the defaultStack, that doesn't work either.我还尝试将StoreInterceptor直接添加到 defaultStack,这也不起作用。

Does StoreInterceptor work not just for saving ActionErrors between Actions, but also between Interceptors and Actions? StoreInterceptor是否不仅用于保存 Actions 之间的ActionErrors ,还用于保存 Interceptor 和 Actions 之间的ActionErrors

The store interceptor works between two actions, one of them store the messages, another retrieve them. store拦截器在两个操作之间工作,其中一个存储消息,另一个检索消息。

In you configuration you have only one action.在您的配置中,您只有一项操作。 The second action should be configured to retrieve messages.第二个操作应配置为检索消息。

The store interceptor doesn't work between action and interceptor or between interceptors. store拦截器在动作和拦截器之间或拦截器之间不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM