1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.struts2.s1;
20
21 import javax.servlet.http.HttpServletRequest;
22
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionMapping;
25 import org.apache.struts2.ServletActionContext;
26 import org.apache.struts2.dispatcher.Dispatcher;
27
28 import com.opensymphony.xwork2.ActionInvocation;
29 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
30 import com.opensymphony.xwork2.interceptor.ScopedModelDriven;
31
32 /***
33 * Calls the reset() method on the ActionForm, if it exists.
34 */
35 public class ActionFormResetInterceptor extends AbstractInterceptor {
36
37 @Override
38 public String intercept(ActionInvocation invocation) throws Exception {
39 Object action = invocation.getAction();
40
41 if (action instanceof ScopedModelDriven) {
42 ScopedModelDriven modelDriven = (ScopedModelDriven) action;
43 Object model = modelDriven.getModel();
44 if (model != null && model instanceof ActionForm) {
45 Struts1Factory factory = new Struts1Factory(Dispatcher.getInstance().getConfigurationManager().getConfiguration());
46 ActionMapping mapping = factory.createActionMapping(invocation.getProxy().getConfig());
47 HttpServletRequest req = ServletActionContext.getRequest();
48 ((ActionForm)model).reset(mapping, req);
49 }
50 }
51 return invocation.invoke();
52 }
53 }