1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.jsf;
22
23 import javax.faces.context.FacesContext;
24 import javax.faces.el.EvaluationException;
25 import javax.faces.el.VariableResolver;
26
27 import com.opensymphony.xwork2.util.OgnlValueStack;
28 import com.opensymphony.xwork2.ActionContext;
29
30 /***
31 * Will return a reference to the current action if the action name matches the
32 * requested variable name. Otherwise it will attempt to resolve the name from
33 * the value stack. Otherwise it will delegate to the original jsf resolver.
34 */
35 public class StrutsVariableResolver extends VariableResolver {
36
37 /*** The original <code>VariableResolver</code> passed to our constructor. */
38 private VariableResolver original = null;
39
40 /*** The variable name of our Struts action */
41 private static final String STRUTS_VARIABLE_NAME = "action";
42
43 /***
44 * Constructor
45 *
46 * @param original
47 * Original resolver to delegate to.
48 */
49 public StrutsVariableResolver(VariableResolver original) {
50
51 this.original = original;
52
53 }
54
55 /***
56 * <p>
57 * Will return a reference to the current action if the action name matches
58 * the requested variable name. Otherwise it will attempt to resolve the
59 * name from the value stack. Otherwise it will delegate to the original jsf
60 * resolver.
61 * </p>
62 *
63 * @param name
64 * Variable name to be resolved
65 */
66 public Object resolveVariable(FacesContext context, String name)
67 throws EvaluationException {
68
69 if (STRUTS_VARIABLE_NAME.equals(name)) {
70 return ActionContext.getContext().getActionInvocation().getAction();
71 }
72
73 Object obj = ActionContext.getContext().getValueStack().findValue(name);
74 if (obj != null) {
75 return obj;
76 } else {
77 return original.resolveVariable(context, name);
78 }
79
80 }
81
82 }