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