1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.component;
20
21 import java.util.Map;
22
23 import javax.el.ValueExpression;
24 import javax.faces.application.Application;
25 import javax.faces.application.ResourceDependencies;
26 import javax.faces.application.ResourceDependency;
27 import javax.faces.context.FacesContext;
28 import javax.faces.convert.Converter;
29
30 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
31 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
32
33
34
35
36 @JSFComponent(defaultRendererType = "javax.faces.Text")
37 public class UIOutput extends UIComponentBase implements ValueHolder
38 {
39 public static final String COMPONENT_TYPE = "javax.faces.Output";
40 public static final String COMPONENT_FAMILY = "javax.faces.Output";
41
42 private Converter _converter;
43
44
45
46
47 public UIOutput()
48 {
49 setRendererType("javax.faces.Text");
50 }
51
52 @Override
53 public String getFamily()
54 {
55 return COMPONENT_FAMILY;
56 }
57
58 public Object getLocalValue()
59 {
60 return getStateHelper().get(PropertyKeys.value);
61 }
62
63
64
65
66
67
68 @JSFProperty
69 public Object getValue()
70 {
71 return getStateHelper().eval(PropertyKeys.value);
72 }
73
74
75
76
77 public void setValue(Object value)
78 {
79 getStateHelper().put(PropertyKeys.value, value );
80 }
81
82
83
84
85
86
87
88
89
90
91 @JSFProperty(partialStateHolder=true)
92 public Converter getConverter()
93 {
94 if (_converter != null)
95 {
96 return _converter;
97 }
98 ValueExpression expression = getValueExpression("converter");
99 if (expression != null)
100 {
101 return (Converter) expression.getValue(getFacesContext().getELContext());
102 }
103 return null;
104 }
105
106 public void setConverter(Converter converter)
107 {
108 this._converter = converter;
109 if (initialStateMarked())
110 {
111 getStateHelper().put(PropertyKeys.converterSet,Boolean.TRUE);
112 }
113
114
115 }
116
117 private boolean _isSetConverter()
118 {
119 Boolean value = (Boolean) getStateHelper().get(PropertyKeys.converterSet);
120 return value == null ? false : value;
121 }
122
123 public void markInitialState()
124 {
125 super.markInitialState();
126 if (_converter != null &&
127 _converter instanceof PartialStateHolder)
128 {
129 ((PartialStateHolder)_converter).markInitialState();
130 }
131 }
132
133 public void clearInitialState()
134 {
135 if (initialStateMarked())
136 {
137 super.clearInitialState();
138 if (_converter != null &&
139 _converter instanceof PartialStateHolder)
140 {
141 ((PartialStateHolder)_converter).clearInitialState();
142 }
143 }
144 }
145
146 enum PropertyKeys
147 {
148 value
149 , converterSet
150 }
151
152 @Override
153 public Object saveState(FacesContext facesContext)
154 {
155 if (initialStateMarked())
156 {
157 Object parentSaved = super.saveState(facesContext);
158 Object converterSaved = null;
159 boolean nullDelta = true;
160 if (!_isSetConverter() &&
161 _converter != null &&
162 _converter instanceof PartialStateHolder)
163 {
164
165 StateHolder holder = (StateHolder) _converter;
166 if (!holder.isTransient())
167 {
168 Object attachedState = holder.saveState(facesContext);
169 if (attachedState != null)
170 {
171 nullDelta = false;
172 }
173 converterSaved = new _AttachedDeltaWrapper(_converter.getClass(),
174 attachedState);
175 }
176 else
177 {
178 converterSaved = null;
179 }
180 }
181 else if (_isSetConverter() || _converter != null)
182 {
183
184 converterSaved = saveAttachedState(facesContext,_converter);
185 nullDelta = false;
186 }
187
188 if (parentSaved == null && nullDelta)
189 {
190
191 return null;
192 }
193 return new Object[]{parentSaved, converterSaved};
194 }
195 else
196 {
197 Object[] values = new Object[2];
198 values[0] = super.saveState(facesContext);
199 values[1] = saveAttachedState(facesContext,_converter);
200 return values;
201 }
202 }
203
204 @Override
205 public void restoreState(FacesContext facesContext, Object state)
206 {
207 if (state == null)
208 {
209 return;
210 }
211
212 Object[] values = (Object[])state;
213 super.restoreState(facesContext,values[0]);
214 if (values[1] instanceof _AttachedDeltaWrapper)
215 {
216
217 ((StateHolder)_converter).restoreState(facesContext, ((_AttachedDeltaWrapper) values[1]).getWrappedStateObject());
218 }
219 else
220 {
221
222 _converter = (javax.faces.convert.Converter) restoreAttachedState(facesContext,values[1]);
223 }
224 }
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310 }