1
2
3
4 package org.rcfaces.core.internal.tools;
5
6 import javax.el.MethodExpression;
7 import javax.el.ValueExpression;
8 import javax.faces.application.Application;
9 import javax.faces.component.UICommand;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.rcfaces.core.internal.listener.IServerActionListener;
16 import org.rcfaces.core.internal.util.ForwardMethodExpression;
17
18
19
20
21
22
23 public class ListenersTools1_2 extends ListenersTools {
24 private static final String REVISION = "$Revision: 1.4.6.1 $";
25
26 private static final Log LOG = LogFactory.getLog(ListenersTools1_2.class);
27
28 private static final Class[] NO_PARAMETER = new Class[0];
29
30 public static void parseListener(FacesContext facesContext,
31 UIComponent component, IListenerType listenerType,
32 ValueExpression expression) {
33 parseListener(facesContext, component, listenerType, expression
34 .getExpressionString(), false, null);
35 }
36
37 public static void parseListener(FacesContext facesContext,
38 UIComponent component, IListenerType listenerType,
39 ValueExpression expression, boolean defaultAction) {
40 parseListener(facesContext, component, listenerType, expression
41 .getExpressionString(), defaultAction, null);
42 }
43
44 public static final void parseAction(FacesContext facesContext,
45 UIComponent component, IListenerType listenerType,
46 ValueExpression expression) {
47 parseAction(facesContext, component, listenerType, expression
48 .getExpressionString(), null);
49 }
50
51 public static final void parseAction(FacesContext facesContext,
52 UIComponent component, IListenerType listenerType,
53 String expression, IMethodExpressionCreator methodExpressionCreator) {
54 expression = expression.trim();
55
56 if (LOG.isDebugEnabled()) {
57 LOG.debug("ParseAction component='" + component
58 + "' listenerType='" + listenerType + "' expression='"
59 + expression + "'.");
60 }
61
62 if (expression.length() < 1) {
63 return;
64 }
65
66 Application application = facesContext.getApplication();
67
68 if (component instanceof UICommand) {
69 UICommand command = (UICommand) component;
70
71 MethodExpression vb;
72
73 if (BindingTools.isBindingExpression(expression)) {
74 if (methodExpressionCreator != null) {
75
76 vb = methodExpressionCreator.create(expression,
77 NO_PARAMETER);
78
79 } else {
80 vb = application.getExpressionFactory()
81 .createMethodExpression(
82 facesContext.getELContext(), expression,
83 null, NO_PARAMETER);
84 }
85
86 } else {
87 vb = new ForwardMethodExpression(expression);
88 }
89
90 if (LOG.isDebugEnabled()) {
91 LOG.debug("Set command action to component '"
92 + component.getId() + "' : " + expression);
93 }
94
95 command.setActionExpression(vb);
96 return;
97 }
98
99 if (BindingTools.isBindingExpression(expression) == false) {
100 expression = "#[" + expression + "]";
101 }
102
103 if (LOG.isDebugEnabled()) {
104 LOG.debug("Add server listener to component '" + component.getId()
105 + "' : " + expression);
106 }
107
108 IServerActionListener serverActionListener = listenerType
109 .addActionListener(component, application, expression, false);
110
111 if (serverActionListener != null && methodExpressionCreator != null) {
112
113 serverActionListener.createMethodExpression(facesContext,
114 methodExpressionCreator);
115 }
116
117 }
118 }