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.component.UIComponent; |
31 | |
import javax.faces.context.FacesContext; |
32 | |
import javax.faces.validator.Validator; |
33 | |
import javax.faces.validator.ValidatorException; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class RedirectMethodExpressionValueExpressionValidator |
40 | |
implements Validator, FacesWrapper<ValueExpression>, Externalizable |
41 | |
{ |
42 | |
private ValueExpression valueExpression; |
43 | |
|
44 | |
public RedirectMethodExpressionValueExpressionValidator() |
45 | 0 | { |
46 | 0 | } |
47 | |
|
48 | |
public RedirectMethodExpressionValueExpressionValidator(ValueExpression valueExpression) |
49 | 0 | { |
50 | 0 | this.valueExpression = valueExpression; |
51 | 0 | } |
52 | |
|
53 | |
public void validate(FacesContext context, UIComponent component, |
54 | |
Object value) throws ValidatorException |
55 | |
{ |
56 | 0 | getMethodExpression().invoke(FacesContext.getCurrentInstance().getELContext(), |
57 | |
new Object[]{context,component,value}); |
58 | 0 | } |
59 | |
|
60 | |
private MethodExpression getMethodExpression() |
61 | |
{ |
62 | 0 | return getMethodExpression(FacesContext.getCurrentInstance().getELContext()); |
63 | |
} |
64 | |
|
65 | |
private MethodExpression getMethodExpression(ELContext context) |
66 | |
{ |
67 | 0 | Object meOrVe = valueExpression.getValue(context); |
68 | 0 | if (meOrVe instanceof MethodExpression) |
69 | |
{ |
70 | 0 | return (MethodExpression) meOrVe; |
71 | |
} |
72 | 0 | else if (meOrVe instanceof ValueExpression) |
73 | |
{ |
74 | 0 | while (meOrVe != null && meOrVe instanceof ValueExpression) |
75 | |
{ |
76 | 0 | meOrVe = ((ValueExpression)meOrVe).getValue(context); |
77 | |
} |
78 | 0 | return (MethodExpression) meOrVe; |
79 | |
} |
80 | |
else |
81 | |
{ |
82 | 0 | return null; |
83 | |
} |
84 | |
} |
85 | |
|
86 | |
public ValueExpression getWrapped() |
87 | |
{ |
88 | 0 | return valueExpression; |
89 | |
} |
90 | |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException |
91 | |
{ |
92 | 0 | this.valueExpression = (ValueExpression) in.readObject(); |
93 | 0 | } |
94 | |
|
95 | |
public void writeExternal(ObjectOutput out) throws IOException |
96 | |
{ |
97 | 0 | out.writeObject(this.valueExpression); |
98 | 0 | } |
99 | |
|
100 | |
} |