1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.event; |
20 | |
|
21 | |
import javax.el.ELContext; |
22 | |
import javax.el.ValueExpression; |
23 | |
import javax.faces.component.StateHolder; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.event.AbortProcessingException; |
26 | |
import javax.faces.event.ActionEvent; |
27 | |
import javax.faces.event.ActionListener; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class SetPropertyActionListener implements ActionListener, StateHolder |
36 | |
{ |
37 | |
|
38 | |
private ValueExpression target; |
39 | |
|
40 | |
private ValueExpression value; |
41 | |
|
42 | |
private boolean _transient ; |
43 | |
|
44 | 0 | public SetPropertyActionListener(){} |
45 | |
|
46 | |
public SetPropertyActionListener(ValueExpression target, ValueExpression value) |
47 | 0 | { |
48 | 0 | this.target = target; |
49 | 0 | this.value = value; |
50 | 0 | } |
51 | |
|
52 | |
public void processAction(ActionEvent actionEvent) throws AbortProcessingException |
53 | |
{ |
54 | |
|
55 | 0 | if( target == null ) |
56 | |
{ |
57 | 0 | throw new AbortProcessingException("@target has not been set"); |
58 | |
} |
59 | |
|
60 | 0 | if( value == null ) |
61 | |
{ |
62 | 0 | throw new AbortProcessingException("@value has not been set"); |
63 | |
} |
64 | |
|
65 | 0 | FacesContext ctx = FacesContext.getCurrentInstance(); |
66 | |
|
67 | 0 | if( ctx == null ) |
68 | |
{ |
69 | 0 | throw new AbortProcessingException("FacesContext ctx is null"); |
70 | |
} |
71 | |
|
72 | 0 | ELContext ectx = ctx.getELContext(); |
73 | |
|
74 | 0 | if( ectx == null ) |
75 | |
{ |
76 | 0 | throw new AbortProcessingException("ELContext ectx is null"); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | 0 | target.setValue(ectx, value.getValue(ectx)); |
82 | |
|
83 | 0 | } |
84 | |
|
85 | |
public Object saveState(FacesContext context) |
86 | |
{ |
87 | 0 | Object[] state = new Object[2]; |
88 | 0 | state[0] = target; |
89 | 0 | state[1] = value; |
90 | 0 | return state; |
91 | |
} |
92 | |
|
93 | |
public void restoreState(FacesContext context, Object state) |
94 | |
{ |
95 | 0 | Object[] values = (Object[]) state; |
96 | 0 | target = (ValueExpression) values[0]; |
97 | 0 | value = (ValueExpression) values[1]; |
98 | 0 | } |
99 | |
|
100 | |
public boolean isTransient() |
101 | |
{ |
102 | 0 | return _transient; |
103 | |
} |
104 | |
|
105 | |
public void setTransient(boolean trans) |
106 | |
{ |
107 | 0 | this._transient = trans; |
108 | 0 | } |
109 | |
|
110 | |
public ValueExpression getTarget() |
111 | |
{ |
112 | 0 | return target; |
113 | |
} |
114 | |
|
115 | |
public void setTarget(ValueExpression target) |
116 | |
{ |
117 | 0 | this.target = target; |
118 | 0 | } |
119 | |
|
120 | |
public ValueExpression getValue() |
121 | |
{ |
122 | 0 | return value; |
123 | |
} |
124 | |
|
125 | |
public void setValue(ValueExpression value) |
126 | |
{ |
127 | 0 | this.value = value; |
128 | 0 | } |
129 | |
|
130 | |
} |