1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.component.html.ext;
20
21 import java.io.IOException;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIData;
28 import javax.faces.component.UIInput;
29 import javax.faces.context.FacesContext;
30 import javax.faces.convert.Converter;
31 import javax.faces.el.MethodBinding;
32 import javax.faces.el.ValueBinding;
33 import javax.faces.event.AbortProcessingException;
34 import javax.faces.event.FacesEvent;
35 import javax.faces.event.FacesListener;
36 import javax.faces.event.ValueChangeListener;
37 import javax.faces.validator.Validator;
38
39 import org.apache.myfaces.shared_tomahawk.component.ExecuteOnCallback;
40
41
42
43
44
45 public class UIComponentPerspective extends UIInput
46 {
47 private boolean enableSetupPerspective = false;
48
49 private UIData uiData;
50 private UIComponent delegate;
51 private int rowIndex;
52 private int oldRowIndex;
53
54 public UIComponentPerspective(UIData uiData, UIComponent delegate, int rowIndex)
55 {
56 super();
57
58 this.enableSetupPerspective = true;
59 this.uiData = uiData;
60 this.rowIndex = rowIndex;
61 this.delegate = delegate;
62 }
63
64 public UIData getUiData()
65 {
66 return uiData;
67 }
68
69 public void setUiData(UIData uiData)
70 {
71 this.uiData = uiData;
72 }
73
74 public int getRowIndex()
75 {
76 return rowIndex;
77 }
78
79 public void setRowIndex(int rowIndex)
80 {
81 this.rowIndex = rowIndex;
82 }
83
84 public Object executeOn(FacesContext context, ExecuteOnCallback callback)
85 {
86 setupPerspective();
87
88 Object retVal;
89
90 if(delegate instanceof UIComponentPerspective)
91 {
92 retVal = ((UIComponentPerspective) delegate).executeOn(context, callback);
93 }
94 else
95 {
96 retVal = callback.execute(context, delegate);
97 }
98 teardownPerspective();
99 return retVal;
100 }
101
102 private UIComponent innerGetDelegate()
103 {
104 if(delegate==null)
105 {
106 delegate = new UIInput();
107 }
108
109 return delegate;
110 }
111
112 private UIInput innerGetDelegateInput()
113 {
114 return (UIInput) delegate;
115 }
116
117 public Map getAttributes()
118 {
119 setupPerspective();
120 Map retVal = innerGetDelegate().getAttributes();
121 teardownPerspective();
122 return retVal;
123 }
124
125 protected void teardownPerspective()
126 {
127 if(enableSetupPerspective)
128 {
129 uiData.setRowIndex(oldRowIndex);
130 }
131 }
132
133 protected void setupPerspective()
134 {
135 if(enableSetupPerspective)
136 {
137 oldRowIndex = uiData.getRowIndex();
138 uiData.setRowIndex(rowIndex);
139 }
140 }
141
142 public ValueBinding getValueBinding(String name)
143 {
144 setupPerspective();
145 ValueBinding retVal = innerGetDelegate().getValueBinding(name);
146 teardownPerspective();
147 return retVal;
148 }
149
150 public void setValueBinding(String name, ValueBinding binding)
151 {
152 setupPerspective();
153 innerGetDelegate().setValueBinding(name, binding);
154 teardownPerspective();
155 }
156
157 public String getClientId(FacesContext context)
158 {
159 setupPerspective();
160 String retVal = innerGetDelegate().getClientId(context);
161 teardownPerspective();
162 return retVal;
163 }
164
165 public String getFamily()
166 {
167 setupPerspective();
168 String retVal = innerGetDelegate().getFamily();
169 teardownPerspective();
170 return retVal;
171 }
172
173 public String getId()
174 {
175 setupPerspective();
176 String retVal = innerGetDelegate().getId();
177 teardownPerspective();
178 return retVal;
179 }
180
181 public void setId(String id)
182 {
183 throw new UnsupportedOperationException("you are not allowed to set the id through the perspective.");
184 }
185
186 public UIComponent getParent()
187 {
188 setupPerspective();
189 UIComponent retVal = innerGetDelegate().getParent();
190 teardownPerspective();
191 return retVal;
192 }
193
194 public void setParent(UIComponent parent)
195 {
196 throw new UnsupportedOperationException("you are not allowed to set the parent through the perspective.");
197 }
198
199 public boolean isRendered()
200 {
201 setupPerspective();
202 boolean retVal = innerGetDelegate().isRendered();
203 teardownPerspective();
204 return retVal;
205 }
206
207 public void setRendered(boolean rendered)
208 {
209 setupPerspective();
210 innerGetDelegate().setRendered(rendered);
211 teardownPerspective();
212 }
213
214 public String getRendererType()
215 {
216 setupPerspective();
217 String rendererType = innerGetDelegate().getRendererType();
218 teardownPerspective();
219 return rendererType;
220 }
221
222 public void setRendererType(String rendererType)
223 {
224 setupPerspective();
225 innerGetDelegate().setRendererType(rendererType);
226 teardownPerspective();
227 }
228
229 public boolean getRendersChildren()
230 {
231 setupPerspective();
232 boolean retVal = innerGetDelegate().getRendersChildren();
233 teardownPerspective();
234 return retVal;
235 }
236
237 public List getChildren()
238 {
239 setupPerspective();
240 List retVal = innerGetDelegate().getChildren();
241 teardownPerspective();
242 return retVal;
243 }
244
245 public int getChildCount()
246 {
247 setupPerspective();
248 int retVal = innerGetDelegate().getChildCount();
249 teardownPerspective();
250 return retVal;
251 }
252
253 public UIComponent findComponent(String expr)
254 {
255 throw new UnsupportedOperationException("you cannot find components via perspectives.");
256 }
257
258 public Map getFacets()
259 {
260 throw new UnsupportedOperationException("you cannot get facets via perspectives.");
261 }
262
263 public UIComponent getFacet(String name)
264 {
265 throw new UnsupportedOperationException("you cannot get a facet via perspectives.");
266 }
267
268 public Iterator getFacetsAndChildren()
269 {
270 throw new UnsupportedOperationException("you cannot find components via perspectives.");
271 }
272
273 public void broadcast(FacesEvent event) throws AbortProcessingException
274 {
275 throw new UnsupportedOperationException("you cannot find broadcast via perspectives.");
276 }
277
278 public void decode(FacesContext context)
279 {
280 setupPerspective();
281 innerGetDelegate().decode(context);
282 teardownPerspective();
283 }
284
285 public void encodeBegin(FacesContext context) throws IOException
286 {
287 setupPerspective();
288 innerGetDelegate().encodeBegin(context);
289 teardownPerspective();
290 }
291
292 public void encodeChildren(FacesContext context) throws IOException
293 {
294 setupPerspective();
295 innerGetDelegate().encodeChildren(context);
296 teardownPerspective();
297 }
298
299 public void encodeEnd(FacesContext context) throws IOException
300 {
301 setupPerspective();
302 innerGetDelegate().encodeEnd(context);
303 teardownPerspective();
304 }
305
306 protected void addFacesListener(FacesListener listener)
307 {
308 throw new UnsupportedOperationException("you cannot add faces listener via perspectives.");
309 }
310
311 protected FacesListener[] getFacesListeners(Class clazz)
312 {
313 throw new UnsupportedOperationException("you cannot get faces listeners via perspectives.");
314 }
315
316 protected void removeFacesListener(FacesListener listener)
317 {
318 throw new UnsupportedOperationException("you cannot remove faces listener via perspectives.");
319 }
320
321 public void queueEvent(FacesEvent event)
322 {
323 throw new UnsupportedOperationException("you cannot queue events via perspectives.");
324 }
325
326 public void processRestoreState(FacesContext context, Object state)
327 {
328 setupPerspective();
329 innerGetDelegate().processRestoreState(context, state);
330 teardownPerspective();
331 }
332
333 public void processDecodes(FacesContext context)
334 {
335 setupPerspective();
336 innerGetDelegate().processDecodes(context);
337 teardownPerspective();
338 }
339
340 public void processValidators(FacesContext context)
341 {
342 setupPerspective();
343 innerGetDelegate().processValidators(context);
344 teardownPerspective();
345 }
346
347 public void processUpdates(FacesContext context)
348 {
349 setupPerspective();
350 innerGetDelegate().processUpdates(context);
351 teardownPerspective();
352 }
353
354 public Object processSaveState(FacesContext context)
355 {
356 setupPerspective();
357 Object retVal=innerGetDelegate().processSaveState(context);
358 teardownPerspective();
359 return retVal;
360 }
361
362
363 public Object saveState(FacesContext context)
364 {
365 setupPerspective();
366 Object retVal=innerGetDelegate().saveState(context);
367 teardownPerspective();
368 return retVal;
369 }
370
371 public void restoreState(FacesContext context, Object state)
372 {
373 setupPerspective();
374 innerGetDelegate().restoreState(context,state);
375 teardownPerspective();
376 }
377
378 public boolean isTransient()
379 {
380 setupPerspective();
381 boolean retVal=innerGetDelegate().isTransient();
382 teardownPerspective();
383 return retVal;
384 }
385
386 public void setTransient(boolean newTransientValue)
387 {
388 setupPerspective();
389 innerGetDelegate().setTransient(newTransientValue);
390 teardownPerspective();
391 }
392
393
394 public Object getSubmittedValue()
395 {
396 setupPerspective();
397 Object retValue = innerGetDelegateInput().getSubmittedValue();
398 teardownPerspective();
399 return retValue;
400 }
401
402
403 public void setSubmittedValue(Object submittedValue)
404 {
405 setupPerspective();
406 innerGetDelegateInput().setSubmittedValue(submittedValue);
407 teardownPerspective();
408 }
409
410 public void setValue(Object value)
411 {
412 setupPerspective();
413 innerGetDelegateInput().setValue(value);
414 teardownPerspective();
415 }
416
417
418 public boolean isLocalValueSet()
419 {
420 setupPerspective();
421 boolean retVal = innerGetDelegateInput().isLocalValueSet();
422 teardownPerspective();
423 return retVal;
424 }
425
426
427 public void setLocalValueSet(boolean localValueSet)
428 {
429 setupPerspective();
430 innerGetDelegateInput().setLocalValueSet(localValueSet);
431 teardownPerspective();
432 }
433
434
435 public boolean isValid()
436 {
437 setupPerspective();
438 boolean retValue=innerGetDelegateInput().isValid();
439 teardownPerspective();
440 return retValue;
441 }
442
443
444 public void setValid(boolean valid)
445 {
446 setupPerspective();
447 innerGetDelegateInput().setValid(valid);
448 teardownPerspective();
449 }
450
451
452 public MethodBinding getValidator()
453 {
454 setupPerspective();
455 MethodBinding validator = innerGetDelegateInput().getValidator();
456 teardownPerspective();
457 return validator;
458 }
459
460
461 public void setValidator(MethodBinding validator)
462 {
463 setupPerspective();
464 innerGetDelegateInput().setValidator(validator);
465 teardownPerspective();
466 }
467
468
469 public MethodBinding getValueChangeListener()
470 {
471 setupPerspective();
472 MethodBinding retValue = innerGetDelegateInput().getValueChangeListener();
473 teardownPerspective();
474 return retValue;
475 }
476
477
478 public void setValueChangeListener(MethodBinding valueChangeListener)
479 {
480 setupPerspective();
481 innerGetDelegateInput().setValueChangeListener(valueChangeListener);
482 teardownPerspective();
483 }
484
485 public void updateModel(FacesContext context)
486 {
487 setupPerspective();
488 innerGetDelegateInput().updateModel(context);
489 teardownPerspective();
490 }
491
492 public void validate(FacesContext context)
493 {
494 setupPerspective();
495 innerGetDelegateInput().validate(context);
496 teardownPerspective();
497 }
498
499
500 public void addValidator(Validator validator)
501 {
502 setupPerspective();
503 innerGetDelegateInput().addValidator(validator);
504 teardownPerspective();
505 }
506
507 public Validator[] getValidators()
508 {
509 setupPerspective();
510 Validator[] retValue = innerGetDelegateInput().getValidators();
511 teardownPerspective();
512 return retValue;
513 }
514
515 public void removeValidator(Validator validator)
516 {
517 setupPerspective();
518 innerGetDelegateInput().removeValidator(validator);
519 teardownPerspective();
520 }
521
522 public void addValueChangeListener(ValueChangeListener listener)
523 {
524 setupPerspective();
525 innerGetDelegateInput().addValueChangeListener(listener);
526 teardownPerspective();
527 }
528
529 public ValueChangeListener[] getValueChangeListeners()
530 {
531 setupPerspective();
532 ValueChangeListener[] listeners = innerGetDelegateInput().getValueChangeListeners();
533 teardownPerspective();
534 return listeners;
535 }
536
537 public void removeValueChangeListener(ValueChangeListener listener)
538 {
539 setupPerspective();
540 innerGetDelegateInput().removeValueChangeListener(listener);
541 teardownPerspective();
542 }
543
544 public void setImmediate(boolean immediate)
545 {
546 setupPerspective();
547 innerGetDelegateInput().setImmediate(immediate);
548 teardownPerspective();
549 }
550
551 public boolean isImmediate()
552 {
553 setupPerspective();
554 boolean retValue = innerGetDelegateInput().isImmediate();
555 teardownPerspective();
556 return retValue;
557 }
558
559 public void setRequired(boolean required)
560 {
561 setupPerspective();
562 innerGetDelegateInput().setRequired(required);
563 teardownPerspective();
564 }
565
566 public boolean isRequired()
567 {
568 setupPerspective();
569 boolean retValue = innerGetDelegateInput().isRequired();
570 teardownPerspective();
571 return retValue;
572 }
573
574 public Object getLocalValue()
575 {
576 setupPerspective();
577 Object retValue = innerGetDelegateInput().getLocalValue();
578 teardownPerspective();
579 return retValue;
580 }
581
582 public void setConverter(Converter converter)
583 {
584 setupPerspective();
585 innerGetDelegateInput().setConverter(converter);
586 teardownPerspective();
587 }
588
589 public Converter getConverter()
590 {
591 setupPerspective();
592 Converter retValue = innerGetDelegateInput().getConverter();
593 teardownPerspective();
594 return retValue;
595 }
596
597 public Object getValue()
598 {
599 setupPerspective();
600 Object retValue = innerGetDelegateInput().getValue();
601 teardownPerspective();
602 return retValue;
603 }
604 }