简体   繁体   中英

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. But that is if you are creating and adding the ActionErrors from within the Action.

My problem is that I am doing a Login using a LoginInterceptor which, if the Login fails, adds an ActionError like so:

((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 .

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):

<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.

Does StoreInterceptor work not just for saving ActionErrors between Actions, but also between Interceptors and Actions?

The store interceptor works between two actions, one of them store the messages, another retrieve them.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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