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