1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.el; |
20 | |
|
21 | |
import java.io.Externalizable; |
22 | |
import java.io.IOException; |
23 | |
import java.io.ObjectInput; |
24 | |
import java.io.ObjectOutput; |
25 | |
|
26 | |
import javax.el.ELContext; |
27 | |
import javax.el.MethodExpression; |
28 | |
import javax.el.ValueExpression; |
29 | |
import javax.faces.FacesWrapper; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import javax.faces.event.AbortProcessingException; |
32 | |
import javax.faces.event.ValueChangeEvent; |
33 | |
import javax.faces.event.ValueChangeListener; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class RedirectMethodExpressionValueExpressionValueChangeListener |
40 | |
implements ValueChangeListener, FacesWrapper<ValueExpression>, Externalizable |
41 | |
{ |
42 | |
private ValueExpression valueExpression; |
43 | |
|
44 | |
public RedirectMethodExpressionValueExpressionValueChangeListener() |
45 | 0 | { |
46 | 0 | } |
47 | |
|
48 | |
public RedirectMethodExpressionValueExpressionValueChangeListener(ValueExpression valueExpression) |
49 | 0 | { |
50 | 0 | this.valueExpression = valueExpression; |
51 | 0 | } |
52 | |
|
53 | |
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException |
54 | |
{ |
55 | 0 | getMethodExpression().invoke(FacesContext.getCurrentInstance().getELContext(), new Object[]{event}); |
56 | 0 | } |
57 | |
|
58 | |
private MethodExpression getMethodExpression() |
59 | |
{ |
60 | 0 | return getMethodExpression(FacesContext.getCurrentInstance().getELContext()); |
61 | |
} |
62 | |
|
63 | |
private MethodExpression getMethodExpression(ELContext context) |
64 | |
{ |
65 | 0 | Object meOrVe = valueExpression.getValue(context); |
66 | 0 | if (meOrVe instanceof MethodExpression) |
67 | |
{ |
68 | 0 | return (MethodExpression) meOrVe; |
69 | |
} |
70 | 0 | else if (meOrVe instanceof ValueExpression) |
71 | |
{ |
72 | 0 | while (meOrVe != null && meOrVe instanceof ValueExpression) |
73 | |
{ |
74 | 0 | meOrVe = ((ValueExpression)meOrVe).getValue(context); |
75 | |
} |
76 | 0 | return (MethodExpression) meOrVe; |
77 | |
} |
78 | |
else |
79 | |
{ |
80 | 0 | return null; |
81 | |
} |
82 | |
} |
83 | |
|
84 | |
public ValueExpression getWrapped() |
85 | |
{ |
86 | 0 | return valueExpression; |
87 | |
} |
88 | |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
89 | |
{ |
90 | 0 | this.valueExpression = (ValueExpression) in.readObject(); |
91 | 0 | } |
92 | |
|
93 | |
public void writeExternal(ObjectOutput out) throws IOException |
94 | |
{ |
95 | 0 | out.writeObject(this.valueExpression); |
96 | 0 | } |
97 | |
|
98 | |
} |