1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.taglib.core; |
20 | |
|
21 | |
import javax.el.ELException; |
22 | |
import javax.el.ValueExpression; |
23 | |
import javax.faces.FacesException; |
24 | |
import javax.faces.component.StateHolder; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.event.AbortProcessingException; |
27 | |
import javax.faces.event.ActionEvent; |
28 | |
import javax.faces.event.ActionListener; |
29 | |
|
30 | |
import org.apache.myfaces.shared.util.ClassUtils; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public class DelegateActionListener implements ActionListener, StateHolder |
51 | |
{ |
52 | |
|
53 | |
private ValueExpression _type; |
54 | |
private ValueExpression _binding; |
55 | |
|
56 | |
public DelegateActionListener() |
57 | 0 | { |
58 | 0 | } |
59 | |
|
60 | |
public DelegateActionListener(ValueExpression type, ValueExpression binding) |
61 | |
{ |
62 | 0 | super(); |
63 | 0 | _type = type; |
64 | 0 | _binding = binding; |
65 | 0 | } |
66 | |
|
67 | |
public boolean isTransient() |
68 | |
{ |
69 | 0 | return false; |
70 | |
} |
71 | |
|
72 | |
public void restoreState(FacesContext facesContext, Object state) |
73 | |
{ |
74 | 0 | Object[] values = (Object[]) state; |
75 | 0 | _type = (ValueExpression) values[0]; |
76 | 0 | _binding = (ValueExpression) values[1]; |
77 | 0 | } |
78 | |
|
79 | |
public Object saveState(FacesContext facesContext) |
80 | |
{ |
81 | 0 | Object[] values = new Object[2]; |
82 | 0 | values[0] = _type; |
83 | 0 | values[1] = _binding; |
84 | 0 | return values; |
85 | |
} |
86 | |
|
87 | |
public void setTransient(boolean arg0) |
88 | |
{ |
89 | |
|
90 | 0 | } |
91 | |
|
92 | |
private ActionListener _getDelegate() |
93 | |
{ |
94 | 0 | return _createActionListener(); |
95 | |
} |
96 | |
|
97 | |
private ActionListener _createActionListener() |
98 | |
{ |
99 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
100 | 0 | ActionListener listener = null; |
101 | |
|
102 | |
try |
103 | |
{ |
104 | 0 | if (null != _binding) |
105 | |
{ |
106 | |
try |
107 | |
{ |
108 | 0 | listener = (ActionListener) _binding.getValue(facesContext |
109 | |
.getELContext()); |
110 | 0 | if (null != listener) |
111 | |
{ |
112 | 0 | return listener; |
113 | |
} |
114 | |
} |
115 | 0 | catch (ELException e) |
116 | |
{ |
117 | 0 | throw new ELException("Exception while evaluating the binding attribute", e); |
118 | 0 | } |
119 | |
} |
120 | 0 | if (null != _type) |
121 | |
{ |
122 | |
String className; |
123 | 0 | if (_type.isLiteralText()) |
124 | |
{ |
125 | 0 | className = _type.getExpressionString(); |
126 | |
} |
127 | |
else |
128 | |
{ |
129 | 0 | className = (String) _type.getValue(facesContext |
130 | |
.getELContext()); |
131 | |
} |
132 | |
|
133 | 0 | listener = (ActionListener) ClassUtils.newInstance(className); |
134 | 0 | if (null != _binding) |
135 | |
{ |
136 | |
try |
137 | |
{ |
138 | 0 | _binding |
139 | |
.setValue(facesContext.getELContext(), listener); |
140 | |
} |
141 | 0 | catch (ELException e) |
142 | |
{ |
143 | 0 | throw new ELException("Exception while evaluating the binding attribute "); |
144 | 0 | } |
145 | |
} |
146 | 0 | return listener; |
147 | |
} |
148 | |
} |
149 | 0 | catch (ClassCastException e) |
150 | |
{ |
151 | 0 | throw new FacesException(e); |
152 | 0 | } |
153 | 0 | return listener; |
154 | |
} |
155 | |
|
156 | |
public void processAction(ActionEvent event) |
157 | |
throws AbortProcessingException |
158 | |
{ |
159 | 0 | _getDelegate().processAction(event); |
160 | 0 | } |
161 | |
|
162 | |
} |