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