1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.chain.commands;
22
23 import java.util.Map;
24
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.chain.contexts.ActionContext;
27 import org.apache.struts.chain.contexts.ServletActionContext;
28 import org.apache.struts.config.ActionConfig;
29 import org.apache.struts.config.FormBeanConfig;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38 public class CreateActionForm extends ActionCommandBase {
39
40
41
42
43
44 private final Logger log =
45 LoggerFactory.getLogger(CreateActionForm.class);
46
47
48
49
50
51
52
53
54
55
56 @Override
57 protected boolean execute_(ActionContext actionCtx)
58 throws Exception {
59
60 ActionConfig actionConfig = actionCtx.getActionConfig();
61 String name = actionConfig.getName();
62
63 if (name == null) {
64 actionCtx.setActionForm(null);
65 return CONTINUE_PROCESSING;
66 }
67
68 log.trace("Look up form-bean {}", name);
69
70
71 FormBeanConfig formBeanConfig =
72 actionConfig.getModuleConfig().findFormBeanConfig(name);
73
74 if (formBeanConfig == null) {
75 log.warn("No FormBeanConfig found in module {} under name {}",
76 actionConfig.getModuleConfig().getPrefix(), name);
77 actionCtx.setActionForm(null);
78 return CONTINUE_PROCESSING;
79 }
80
81 Map<String, Object> scope = actionCtx.getScope(actionConfig.getScope());
82
83 ActionForm instance;
84
85 instance = (ActionForm) scope.get(actionConfig.getAttribute());
86
87
88 if (!formBeanConfig.canReuse(instance)) {
89 instance = formBeanConfig.createActionForm(actionCtx);
90 }
91
92
93
94 if (actionCtx instanceof ServletActionContext) {
95
96
97
98 ServletActionContext sac = (ServletActionContext) actionCtx;
99
100 instance.setServlet(sac.getActionServlet());
101 }
102
103 actionCtx.setActionForm(instance);
104
105 scope.put(actionConfig.getAttribute(), instance);
106
107 return CONTINUE_PROCESSING;
108 }
109 }