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.io.IOException; |
22 | |
import java.sql.ResultSet; |
23 | |
import java.util.*; |
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.faces.FacesException; |
26 | |
import javax.faces.application.FacesMessage; |
27 | |
import javax.faces.context.FacesContext; |
28 | |
import javax.faces.event.AbortProcessingException; |
29 | |
import javax.faces.event.FacesEvent; |
30 | |
import javax.faces.event.FacesListener; |
31 | |
import javax.faces.event.PhaseId; |
32 | |
import javax.faces.model.*; |
33 | |
import javax.servlet.jsp.jstl.sql.Result; |
34 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent; |
35 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFacet; |
36 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
@JSFComponent(defaultRendererType = "javax.faces.Table") |
104 | |
public class UIData extends UIComponentBase |
105 | |
implements NamingContainer |
106 | |
{ |
107 | |
public static final String COMPONENT_FAMILY = "javax.faces.Data"; |
108 | |
public static final String COMPONENT_TYPE = "javax.faces.Data"; |
109 | |
|
110 | |
private static final String FOOTER_FACET_NAME = "footer"; |
111 | |
private static final String HEADER_FACET_NAME = "header"; |
112 | 0 | private static final Class OBJECT_ARRAY_CLASS = (new Object[0]).getClass(); |
113 | |
private static final int PROCESS_DECODES = 1; |
114 | |
private static final int PROCESS_VALIDATORS = 2; |
115 | |
private static final int PROCESS_UPDATES = 3; |
116 | |
|
117 | 0 | private int _rowIndex = -1; |
118 | |
private String _var; |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | 0 | private Map _rowStates = new HashMap(); |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | 0 | private Map _dataModelMap = new HashMap(); |
133 | |
|
134 | |
|
135 | 0 | private boolean _isValidChilds = true; |
136 | |
|
137 | 0 | private Object _initialDescendantComponentState = null; |
138 | |
|
139 | |
private int _first; |
140 | |
private boolean _firstSet; |
141 | |
private int _rows; |
142 | |
private boolean _rowsSet; |
143 | |
private Object _value; |
144 | |
|
145 | |
private static class FacesEventWrapper extends FacesEvent |
146 | |
{ |
147 | |
private static final long serialVersionUID = 6648047974065628773L; |
148 | |
private FacesEvent _wrappedFacesEvent; |
149 | |
private int _rowIndex; |
150 | |
|
151 | |
public FacesEventWrapper(FacesEvent facesEvent, int rowIndex, |
152 | |
UIData redirectComponent) |
153 | |
{ |
154 | 0 | super(redirectComponent); |
155 | 0 | _wrappedFacesEvent = facesEvent; |
156 | 0 | _rowIndex = rowIndex; |
157 | 0 | } |
158 | |
|
159 | |
@Override |
160 | |
public PhaseId getPhaseId() |
161 | |
{ |
162 | 0 | return _wrappedFacesEvent.getPhaseId(); |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public void setPhaseId(PhaseId phaseId) |
167 | |
{ |
168 | 0 | _wrappedFacesEvent.setPhaseId(phaseId); |
169 | 0 | } |
170 | |
|
171 | |
@Override |
172 | |
public void queue() |
173 | |
{ |
174 | 0 | _wrappedFacesEvent.queue(); |
175 | 0 | } |
176 | |
|
177 | |
@Override |
178 | |
public String toString() |
179 | |
{ |
180 | 0 | return _wrappedFacesEvent.toString(); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public boolean isAppropriateListener(FacesListener faceslistener) |
185 | |
{ |
186 | 0 | return _wrappedFacesEvent.isAppropriateListener(faceslistener); |
187 | |
} |
188 | |
|
189 | |
@Override |
190 | |
public void processListener(FacesListener faceslistener) |
191 | |
{ |
192 | 0 | _wrappedFacesEvent.processListener(faceslistener); |
193 | 0 | } |
194 | |
|
195 | |
public FacesEvent getWrappedFacesEvent() |
196 | |
{ |
197 | 0 | return _wrappedFacesEvent; |
198 | |
} |
199 | |
|
200 | |
public int getRowIndex() |
201 | |
{ |
202 | 0 | return _rowIndex; |
203 | |
} |
204 | |
} |
205 | |
|
206 | |
|
207 | 0 | private static final DataModel EMPTY_DATA_MODEL = new DataModel() |
208 | 0 | { |
209 | |
@Override |
210 | |
public boolean isRowAvailable() |
211 | |
{ |
212 | 0 | return false; |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public int getRowCount() |
217 | |
{ |
218 | 0 | return 0; |
219 | |
} |
220 | |
|
221 | |
@Override |
222 | |
public Object getRowData() |
223 | |
{ |
224 | 0 | throw new IllegalArgumentException(); |
225 | |
} |
226 | |
|
227 | |
@Override |
228 | |
public int getRowIndex() |
229 | |
{ |
230 | 0 | return -1; |
231 | |
} |
232 | |
|
233 | |
@Override |
234 | |
public void setRowIndex(int i) |
235 | |
{ |
236 | 0 | if (i < -1) |
237 | 0 | throw new IllegalArgumentException(); |
238 | 0 | } |
239 | |
|
240 | |
@Override |
241 | |
public Object getWrappedData() |
242 | |
{ |
243 | 0 | return null; |
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public void setWrappedData(Object obj) |
248 | |
{ |
249 | 0 | if (obj == null) |
250 | |
{ |
251 | 0 | return; |
252 | |
} |
253 | 0 | throw new UnsupportedOperationException(this.getClass().getName() |
254 | |
+ " UnsupportedOperationException"); |
255 | |
} |
256 | |
}; |
257 | |
|
258 | |
private class EditableValueHolderState |
259 | |
{ |
260 | |
private final Object _value; |
261 | |
private final boolean _localValueSet; |
262 | |
private final boolean _valid; |
263 | |
private final Object _submittedValue; |
264 | |
|
265 | |
public EditableValueHolderState(EditableValueHolder evh) |
266 | 0 | { |
267 | 0 | _value = evh.getLocalValue(); |
268 | 0 | _localValueSet = evh.isLocalValueSet(); |
269 | 0 | _valid = evh.isValid(); |
270 | 0 | _submittedValue = evh.getSubmittedValue(); |
271 | 0 | } |
272 | |
|
273 | |
public void restoreState(EditableValueHolder evh) |
274 | |
{ |
275 | 0 | evh.setValue(_value); |
276 | 0 | evh.setLocalValueSet(_localValueSet); |
277 | 0 | evh.setValid(_valid); |
278 | 0 | evh.setSubmittedValue(_submittedValue); |
279 | 0 | } |
280 | |
} |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
public UIData() |
286 | 0 | { |
287 | 0 | setRendererType("javax.faces.Table"); |
288 | 0 | } |
289 | |
|
290 | |
@Override |
291 | |
public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback) throws FacesException { |
292 | 0 | if (context == null || clientId == null || callback == null) |
293 | |
{ |
294 | 0 | throw new NullPointerException(); |
295 | |
} |
296 | |
|
297 | |
|
298 | 0 | boolean returnValue = this.getClientId(context).equals(clientId); |
299 | |
|
300 | 0 | boolean isCachedFacesContext = isCachedFacesContext(); |
301 | 0 | if (!isCachedFacesContext) |
302 | |
{ |
303 | 0 | setCachedFacesContext(context); |
304 | |
} |
305 | |
|
306 | |
try |
307 | |
{ |
308 | 0 | if (returnValue) |
309 | |
{ |
310 | |
try |
311 | |
{ |
312 | 0 | callback.invokeContextCallback(context, this); |
313 | |
} |
314 | 0 | catch (Exception e) |
315 | |
{ |
316 | 0 | throw new FacesException(e); |
317 | 0 | } |
318 | 0 | return returnValue; |
319 | |
} |
320 | |
|
321 | |
|
322 | 0 | for (Iterator<UIComponent> it = this.getFacets().values().iterator(); !returnValue && it.hasNext();) |
323 | |
{ |
324 | 0 | returnValue = it.next().invokeOnComponent(context, clientId, callback); |
325 | |
} |
326 | |
|
327 | 0 | if (returnValue == true) |
328 | |
{ |
329 | 0 | return returnValue; |
330 | |
} |
331 | |
|
332 | |
|
333 | 0 | String baseClientId = super.getClientId(context); |
334 | |
|
335 | |
|
336 | 0 | if (clientId.startsWith(baseClientId)) |
337 | |
{ |
338 | |
|
339 | |
|
340 | 0 | String subId = clientId.substring(baseClientId.length() + 1); |
341 | |
|
342 | |
|
343 | 0 | if (clientId.charAt(baseClientId.length()) == NamingContainer.SEPARATOR_CHAR && |
344 | |
subId.matches("[0-9]+"+NamingContainer.SEPARATOR_CHAR+".*")) |
345 | |
{ |
346 | 0 | String clientRow = subId.substring(0, subId.indexOf(NamingContainer.SEPARATOR_CHAR)); |
347 | |
|
348 | |
|
349 | 0 | int oldRow = this.getRowIndex(); |
350 | |
|
351 | |
|
352 | |
try |
353 | |
{ |
354 | |
|
355 | |
|
356 | 0 | this.setRowIndex(Integer.parseInt(clientRow)); |
357 | |
|
358 | |
|
359 | 0 | if (!isRowAvailable()) |
360 | |
{ |
361 | 0 | return false; |
362 | |
} |
363 | |
|
364 | 0 | for (Iterator<UIComponent> it1 = getChildren().iterator(); |
365 | 0 | !returnValue && it1.hasNext();) |
366 | |
{ |
367 | |
|
368 | 0 | returnValue = it1.next().invokeOnComponent(context, clientId, callback); |
369 | |
} |
370 | |
} |
371 | |
finally |
372 | |
{ |
373 | |
|
374 | |
|
375 | 0 | this.setRowIndex(oldRow); |
376 | 0 | } |
377 | 0 | } |
378 | |
else |
379 | |
{ |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | 0 | for (Iterator<UIComponent> itChildren = this.getChildren().iterator(); |
386 | 0 | !returnValue && itChildren.hasNext();) |
387 | |
{ |
388 | 0 | UIComponent child = itChildren.next(); |
389 | 0 | if (child instanceof UIColumn && clientId.equals(child.getClientId(context))) |
390 | |
{ |
391 | |
try { |
392 | 0 | callback.invokeContextCallback(context, child); |
393 | 0 | } catch (Exception e) { |
394 | 0 | throw new FacesException(e); |
395 | 0 | } |
396 | 0 | returnValue = true; |
397 | |
} |
398 | |
|
399 | 0 | for (Iterator<UIComponent> itChildFacets = child.getFacets().values().iterator(); |
400 | 0 | !returnValue && itChildFacets.hasNext();) |
401 | |
{ |
402 | |
|
403 | 0 | returnValue = itChildFacets.next().invokeOnComponent(context, clientId, callback); |
404 | |
} |
405 | 0 | } |
406 | |
} |
407 | |
} |
408 | |
} |
409 | |
finally |
410 | |
{ |
411 | 0 | if (!isCachedFacesContext) |
412 | |
{ |
413 | 0 | setCachedFacesContext(null); |
414 | |
} |
415 | |
} |
416 | |
|
417 | 0 | return returnValue; |
418 | |
} |
419 | |
|
420 | |
public void setFooter(UIComponent footer) |
421 | |
{ |
422 | 0 | getFacets().put(FOOTER_FACET_NAME, footer); |
423 | 0 | } |
424 | |
|
425 | |
@JSFFacet |
426 | |
public UIComponent getFooter() |
427 | |
{ |
428 | 0 | return (UIComponent) getFacets().get(FOOTER_FACET_NAME); |
429 | |
} |
430 | |
|
431 | |
public void setHeader(UIComponent header) |
432 | |
{ |
433 | 0 | getFacets().put(HEADER_FACET_NAME, header); |
434 | 0 | } |
435 | |
|
436 | |
@JSFFacet |
437 | |
public UIComponent getHeader() |
438 | |
{ |
439 | 0 | return (UIComponent) getFacets().get(HEADER_FACET_NAME); |
440 | |
} |
441 | |
|
442 | |
public boolean isRowAvailable() |
443 | |
{ |
444 | 0 | return getDataModel().isRowAvailable(); |
445 | |
} |
446 | |
|
447 | |
public int getRowCount() |
448 | |
{ |
449 | 0 | return getDataModel().getRowCount(); |
450 | |
} |
451 | |
|
452 | |
public Object getRowData() |
453 | |
{ |
454 | 0 | return getDataModel().getRowData(); |
455 | |
} |
456 | |
|
457 | |
public int getRowIndex() |
458 | |
{ |
459 | 0 | return _rowIndex; |
460 | |
} |
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
public void setRowIndex(int rowIndex) |
470 | |
{ |
471 | 0 | if (rowIndex < -1) |
472 | |
{ |
473 | 0 | throw new IllegalArgumentException("rowIndex is less than -1"); |
474 | |
} |
475 | |
|
476 | 0 | if (_rowIndex == rowIndex) |
477 | |
{ |
478 | 0 | return; |
479 | |
} |
480 | |
|
481 | 0 | FacesContext facesContext = getFacesContext(); |
482 | |
|
483 | 0 | if (_rowIndex == -1) |
484 | |
{ |
485 | 0 | if (_initialDescendantComponentState == null) |
486 | |
{ |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | 0 | _initialDescendantComponentState = saveDescendantComponentStates( |
492 | |
getChildren().iterator(), false); |
493 | |
} |
494 | |
} |
495 | |
else |
496 | |
{ |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | 0 | _rowStates.put(getClientId(facesContext), |
502 | |
saveDescendantComponentStates(getChildren().iterator(), |
503 | |
false)); |
504 | |
} |
505 | |
|
506 | 0 | _rowIndex = rowIndex; |
507 | |
|
508 | 0 | DataModel dataModel = getDataModel(); |
509 | 0 | dataModel.setRowIndex(rowIndex); |
510 | |
|
511 | 0 | String var = _var; |
512 | 0 | if (rowIndex == -1) |
513 | |
{ |
514 | 0 | if (var != null) |
515 | |
{ |
516 | 0 | facesContext.getExternalContext().getRequestMap().remove(var); |
517 | |
} |
518 | |
} |
519 | |
else |
520 | |
{ |
521 | 0 | if (var != null) |
522 | |
{ |
523 | 0 | if (isRowAvailable()) |
524 | |
{ |
525 | 0 | Object rowData = dataModel.getRowData(); |
526 | 0 | facesContext.getExternalContext().getRequestMap().put(var, |
527 | |
rowData); |
528 | 0 | } |
529 | |
else |
530 | |
{ |
531 | 0 | facesContext.getExternalContext().getRequestMap().remove( |
532 | |
var); |
533 | |
} |
534 | |
} |
535 | |
} |
536 | |
|
537 | 0 | if (_rowIndex == -1) |
538 | |
{ |
539 | |
|
540 | 0 | restoreDescendantComponentStates(getChildren().iterator(), |
541 | |
_initialDescendantComponentState, false); |
542 | |
} |
543 | |
else |
544 | |
{ |
545 | 0 | Object rowState = _rowStates.get(getClientId(facesContext)); |
546 | 0 | if (rowState == null) |
547 | |
{ |
548 | |
|
549 | |
|
550 | |
|
551 | 0 | restoreDescendantComponentStates(getChildren().iterator(), |
552 | |
_initialDescendantComponentState, false); |
553 | |
} |
554 | |
else |
555 | |
{ |
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | 0 | restoreDescendantComponentStates(getChildren().iterator(), |
561 | |
rowState, false); |
562 | |
} |
563 | |
} |
564 | 0 | } |
565 | |
|
566 | |
|
567 | |
|
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
private void restoreDescendantComponentStates(Iterator childIterator, |
574 | |
Object state, boolean restoreChildFacets) |
575 | |
{ |
576 | 0 | Iterator descendantStateIterator = null; |
577 | 0 | while (childIterator.hasNext()) |
578 | |
{ |
579 | 0 | if (descendantStateIterator == null && state != null) |
580 | |
{ |
581 | 0 | descendantStateIterator = ((Collection) state).iterator(); |
582 | |
} |
583 | 0 | UIComponent component = (UIComponent) childIterator.next(); |
584 | |
|
585 | |
|
586 | 0 | component.setId(component.getId()); |
587 | 0 | if(!component.isTransient()) |
588 | |
{ |
589 | 0 | Object childState = null; |
590 | 0 | Object descendantState = null; |
591 | 0 | if (descendantStateIterator != null |
592 | |
&& descendantStateIterator.hasNext()) |
593 | |
{ |
594 | 0 | Object[] object = (Object[]) descendantStateIterator.next(); |
595 | 0 | childState = object[0]; |
596 | 0 | descendantState = object[1]; |
597 | |
} |
598 | 0 | if (component instanceof EditableValueHolder) |
599 | |
{ |
600 | 0 | ((EditableValueHolderState) childState) |
601 | |
.restoreState((EditableValueHolder) component); |
602 | |
} |
603 | |
Iterator childsIterator; |
604 | 0 | if (restoreChildFacets) |
605 | |
{ |
606 | 0 | childsIterator = component.getFacetsAndChildren(); |
607 | |
} |
608 | |
else |
609 | |
{ |
610 | 0 | childsIterator = component.getChildren().iterator(); |
611 | |
} |
612 | 0 | restoreDescendantComponentStates(childsIterator, descendantState, |
613 | |
true); |
614 | |
} |
615 | 0 | } |
616 | 0 | } |
617 | |
|
618 | |
|
619 | |
|
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
private Object saveDescendantComponentStates(Iterator childIterator, |
636 | |
boolean saveChildFacets) |
637 | |
{ |
638 | 0 | Collection childStates = null; |
639 | 0 | while (childIterator.hasNext()) |
640 | |
{ |
641 | 0 | if (childStates == null) |
642 | |
{ |
643 | 0 | childStates = new ArrayList(); |
644 | |
} |
645 | 0 | UIComponent child = (UIComponent) childIterator.next(); |
646 | 0 | if(!child.isTransient()) |
647 | |
{ |
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
Iterator childsIterator; |
654 | 0 | if (saveChildFacets) |
655 | |
{ |
656 | 0 | childsIterator = child.getFacetsAndChildren(); |
657 | |
} |
658 | |
else |
659 | |
{ |
660 | 0 | childsIterator = child.getChildren().iterator(); |
661 | |
} |
662 | 0 | Object descendantState = saveDescendantComponentStates( |
663 | |
childsIterator, true); |
664 | 0 | Object state = null; |
665 | 0 | if (child instanceof EditableValueHolder) |
666 | |
{ |
667 | 0 | state = new EditableValueHolderState( |
668 | |
(EditableValueHolder) child); |
669 | |
} |
670 | 0 | childStates.add(new Object[] { state, descendantState }); |
671 | |
} |
672 | 0 | } |
673 | 0 | return childStates; |
674 | |
} |
675 | |
|
676 | |
@Override |
677 | |
public void setValueExpression(String name, ValueExpression binding) { |
678 | 0 | if (name == null) |
679 | |
{ |
680 | 0 | throw new NullPointerException("name"); |
681 | |
} |
682 | 0 | else if (name.equals("value")) |
683 | |
{ |
684 | 0 | _dataModelMap.clear(); |
685 | |
} |
686 | 0 | else if (name.equals("rowIndex")) |
687 | |
{ |
688 | 0 | throw new IllegalArgumentException("name " + name); |
689 | |
} |
690 | 0 | super.setValueExpression(name, binding); |
691 | 0 | } |
692 | |
|
693 | |
@Override |
694 | |
public String getClientId(FacesContext context) |
695 | |
{ |
696 | 0 | String clientId = super.getClientId(context); |
697 | 0 | int rowIndex = getRowIndex(); |
698 | 0 | if (rowIndex == -1) |
699 | |
{ |
700 | 0 | return clientId; |
701 | |
} |
702 | |
|
703 | 0 | StringBuilder bld = __getSharedStringBuilder(); |
704 | 0 | return bld.append(clientId).append(NamingContainer.SEPARATOR_CHAR).append(rowIndex).toString(); |
705 | |
} |
706 | |
|
707 | |
|
708 | |
|
709 | |
|
710 | |
|
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
@Override |
727 | |
public void queueEvent(FacesEvent event) |
728 | |
{ |
729 | 0 | super.queueEvent(new FacesEventWrapper(event, getRowIndex(), this)); |
730 | 0 | } |
731 | |
|
732 | |
|
733 | |
|
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
@Override |
739 | |
public void broadcast(FacesEvent event) throws AbortProcessingException |
740 | |
{ |
741 | 0 | if (event instanceof FacesEventWrapper) |
742 | |
{ |
743 | 0 | FacesEvent originalEvent = ((FacesEventWrapper) event) |
744 | |
.getWrappedFacesEvent(); |
745 | 0 | int eventRowIndex = ((FacesEventWrapper) event).getRowIndex(); |
746 | 0 | int currentRowIndex = getRowIndex(); |
747 | 0 | setRowIndex(eventRowIndex); |
748 | |
try |
749 | |
{ |
750 | 0 | originalEvent.getComponent().broadcast(originalEvent); |
751 | |
} |
752 | |
finally |
753 | |
{ |
754 | 0 | setRowIndex(currentRowIndex); |
755 | 0 | } |
756 | 0 | } |
757 | |
else |
758 | |
{ |
759 | 0 | super.broadcast(event); |
760 | |
} |
761 | 0 | } |
762 | |
|
763 | |
|
764 | |
|
765 | |
|
766 | |
|
767 | |
|
768 | |
@Override |
769 | |
public void encodeBegin(FacesContext context) throws IOException |
770 | |
{ |
771 | 0 | _initialDescendantComponentState = null; |
772 | 0 | if (_isValidChilds && !hasErrorMessages(context)) |
773 | |
{ |
774 | |
|
775 | |
|
776 | |
|
777 | 0 | _dataModelMap.clear(); |
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | 0 | _rowStates.clear(); |
784 | |
} |
785 | 0 | super.encodeBegin(context); |
786 | 0 | } |
787 | |
|
788 | |
private boolean hasErrorMessages(FacesContext context) |
789 | |
{ |
790 | 0 | for(Iterator iter = context.getMessages(); iter.hasNext();) |
791 | |
{ |
792 | 0 | FacesMessage message = (FacesMessage) iter.next(); |
793 | 0 | if(FacesMessage.SEVERITY_ERROR.compareTo(message.getSeverity()) <= 0) |
794 | |
{ |
795 | 0 | return true; |
796 | |
} |
797 | 0 | } |
798 | 0 | return false; |
799 | |
} |
800 | |
|
801 | |
|
802 | |
|
803 | |
|
804 | |
@Override |
805 | |
public void encodeEnd(FacesContext context) throws IOException |
806 | |
{ |
807 | |
try |
808 | |
{ |
809 | 0 | setCachedFacesContext(context); |
810 | 0 | setRowIndex(-1); |
811 | |
} |
812 | |
finally |
813 | |
{ |
814 | 0 | setCachedFacesContext(null); |
815 | 0 | } |
816 | 0 | super.encodeEnd(context); |
817 | 0 | } |
818 | |
|
819 | |
@Override |
820 | |
public void processDecodes(FacesContext context) |
821 | |
{ |
822 | 0 | if (context == null) |
823 | |
{ |
824 | 0 | throw new NullPointerException("context"); |
825 | |
} |
826 | |
try |
827 | |
{ |
828 | 0 | setCachedFacesContext(context); |
829 | 0 | if (!isRendered()) |
830 | |
{ |
831 | |
return; |
832 | |
} |
833 | 0 | setRowIndex(-1); |
834 | 0 | processFacets(context, PROCESS_DECODES); |
835 | 0 | processColumnFacets(context, PROCESS_DECODES); |
836 | 0 | processColumnChildren(context, PROCESS_DECODES); |
837 | 0 | setRowIndex(-1); |
838 | |
try |
839 | |
{ |
840 | 0 | decode(context); |
841 | |
} |
842 | 0 | catch (RuntimeException e) |
843 | |
{ |
844 | 0 | context.renderResponse(); |
845 | 0 | throw e; |
846 | 0 | } |
847 | |
} |
848 | |
finally |
849 | |
{ |
850 | 0 | setCachedFacesContext(null); |
851 | 0 | } |
852 | 0 | } |
853 | |
|
854 | |
@Override |
855 | |
public void processValidators(FacesContext context) |
856 | |
{ |
857 | 0 | if (context == null) |
858 | |
{ |
859 | 0 | throw new NullPointerException("context"); |
860 | |
} |
861 | |
|
862 | |
try |
863 | |
{ |
864 | 0 | setCachedFacesContext(context); |
865 | 0 | if (!isRendered()) |
866 | |
{ |
867 | |
return; |
868 | |
} |
869 | |
|
870 | 0 | setRowIndex(-1); |
871 | 0 | processFacets(context, PROCESS_VALIDATORS); |
872 | 0 | processColumnFacets(context, PROCESS_VALIDATORS); |
873 | 0 | processColumnChildren(context, PROCESS_VALIDATORS); |
874 | 0 | setRowIndex(-1); |
875 | |
|
876 | |
|
877 | 0 | if (context.getRenderResponse()) |
878 | |
{ |
879 | 0 | _isValidChilds = false; |
880 | |
} |
881 | |
} |
882 | |
finally |
883 | |
{ |
884 | 0 | setCachedFacesContext(null); |
885 | 0 | } |
886 | 0 | } |
887 | |
|
888 | |
@Override |
889 | |
public void processUpdates(FacesContext context) |
890 | |
{ |
891 | 0 | if (context == null) |
892 | |
{ |
893 | 0 | throw new NullPointerException("context"); |
894 | |
} |
895 | |
try |
896 | |
{ |
897 | 0 | setCachedFacesContext(context); |
898 | 0 | if (!isRendered()) |
899 | |
{ |
900 | |
return; |
901 | |
} |
902 | 0 | setRowIndex(-1); |
903 | 0 | processFacets(context, PROCESS_UPDATES); |
904 | 0 | processColumnFacets(context, PROCESS_UPDATES); |
905 | 0 | processColumnChildren(context, PROCESS_UPDATES); |
906 | 0 | setRowIndex(-1); |
907 | |
|
908 | 0 | if (context.getRenderResponse()) |
909 | |
{ |
910 | 0 | _isValidChilds = false; |
911 | |
} |
912 | |
} |
913 | |
finally |
914 | |
{ |
915 | 0 | setCachedFacesContext(null); |
916 | 0 | } |
917 | 0 | } |
918 | |
|
919 | |
private void processFacets(FacesContext context, int processAction) |
920 | |
{ |
921 | 0 | for (Iterator it = getFacets().values().iterator(); it.hasNext();) |
922 | |
{ |
923 | 0 | UIComponent facet = (UIComponent) it.next(); |
924 | 0 | process(context, facet, processAction); |
925 | 0 | } |
926 | 0 | } |
927 | |
|
928 | |
|
929 | |
|
930 | |
|
931 | |
|
932 | |
|
933 | |
|
934 | |
|
935 | |
|
936 | |
private void processColumnFacets(FacesContext context, int processAction) |
937 | |
{ |
938 | 0 | for (Iterator childIter = getChildren().iterator(); childIter.hasNext();) |
939 | |
{ |
940 | 0 | UIComponent child = (UIComponent) childIter.next(); |
941 | 0 | if (child instanceof UIColumn) |
942 | |
{ |
943 | 0 | if (!child.isRendered()) |
944 | |
{ |
945 | |
|
946 | 0 | continue; |
947 | |
} |
948 | 0 | for (Iterator facetsIter = child.getFacets().values() |
949 | 0 | .iterator(); facetsIter.hasNext();) |
950 | |
{ |
951 | 0 | UIComponent facet = (UIComponent) facetsIter.next(); |
952 | 0 | process(context, facet, processAction); |
953 | 0 | } |
954 | |
} |
955 | 0 | } |
956 | 0 | } |
957 | |
|
958 | |
|
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | |
|
966 | |
private void processColumnChildren(FacesContext context, int processAction) |
967 | |
{ |
968 | 0 | int first = getFirst(); |
969 | 0 | int rows = getRows(); |
970 | |
int last; |
971 | 0 | if (rows == 0) |
972 | |
{ |
973 | 0 | last = getRowCount(); |
974 | |
} |
975 | |
else |
976 | |
{ |
977 | 0 | last = first + rows; |
978 | |
} |
979 | 0 | for (int rowIndex = first; last==-1 || rowIndex < last; rowIndex++) |
980 | |
{ |
981 | 0 | setRowIndex(rowIndex); |
982 | |
|
983 | |
|
984 | 0 | if (!isRowAvailable()) |
985 | |
{ |
986 | 0 | break; |
987 | |
} |
988 | |
|
989 | 0 | for (Iterator it = getChildren().iterator(); it.hasNext();) |
990 | |
{ |
991 | 0 | UIComponent child = (UIComponent) it.next(); |
992 | 0 | if (child instanceof UIColumn) |
993 | |
{ |
994 | 0 | if (!child.isRendered()) |
995 | |
{ |
996 | |
|
997 | 0 | continue; |
998 | |
} |
999 | 0 | for (Iterator columnChildIter = child.getChildren() |
1000 | 0 | .iterator(); columnChildIter.hasNext();) |
1001 | |
{ |
1002 | 0 | UIComponent columnChild = (UIComponent) columnChildIter |
1003 | |
.next(); |
1004 | 0 | process(context, columnChild, processAction); |
1005 | 0 | } |
1006 | |
} |
1007 | 0 | } |
1008 | |
} |
1009 | 0 | } |
1010 | |
|
1011 | |
private void process(FacesContext context, UIComponent component, |
1012 | |
int processAction) |
1013 | |
{ |
1014 | 0 | switch (processAction) |
1015 | |
{ |
1016 | |
case PROCESS_DECODES: |
1017 | 0 | component.processDecodes(context); |
1018 | 0 | break; |
1019 | |
case PROCESS_VALIDATORS: |
1020 | 0 | component.processValidators(context); |
1021 | 0 | break; |
1022 | |
case PROCESS_UPDATES: |
1023 | 0 | component.processUpdates(context); |
1024 | |
break; |
1025 | |
} |
1026 | 0 | } |
1027 | |
|
1028 | |
|
1029 | |
|
1030 | |
|
1031 | |
|
1032 | |
|
1033 | |
|
1034 | |
|
1035 | |
|
1036 | |
|
1037 | |
|
1038 | |
|
1039 | |
|
1040 | |
|
1041 | |
|
1042 | |
|
1043 | |
protected DataModel getDataModel() |
1044 | |
{ |
1045 | |
DataModel dataModel; |
1046 | 0 | String clientID = ""; |
1047 | |
|
1048 | 0 | UIComponent parent = getParent(); |
1049 | 0 | if (parent != null) |
1050 | |
{ |
1051 | 0 | clientID = parent.getClientId(getFacesContext()); |
1052 | |
} |
1053 | 0 | dataModel = (DataModel) _dataModelMap.get(clientID); |
1054 | 0 | if (dataModel == null) |
1055 | |
{ |
1056 | 0 | dataModel = createDataModel(); |
1057 | 0 | _dataModelMap.put(clientID, dataModel); |
1058 | |
} |
1059 | 0 | return dataModel; |
1060 | |
} |
1061 | |
|
1062 | |
protected void setDataModel(DataModel dataModel) |
1063 | |
{ |
1064 | 0 | throw new UnsupportedOperationException( |
1065 | |
"this method is here only to maintain binary compatibility w/ the RI"); |
1066 | |
} |
1067 | |
|
1068 | |
|
1069 | |
|
1070 | |
|
1071 | |
|
1072 | |
|
1073 | |
|
1074 | |
|
1075 | |
|
1076 | |
|
1077 | |
|
1078 | |
|
1079 | |
|
1080 | |
private DataModel createDataModel() |
1081 | |
{ |
1082 | 0 | Object value = getValue(); |
1083 | |
|
1084 | 0 | if (value == null) |
1085 | |
{ |
1086 | 0 | return EMPTY_DATA_MODEL; |
1087 | |
} |
1088 | 0 | else if (value instanceof DataModel) |
1089 | |
{ |
1090 | 0 | return (DataModel) value; |
1091 | |
} |
1092 | 0 | else if (value instanceof List) |
1093 | |
{ |
1094 | 0 | return new ListDataModel((List) value); |
1095 | |
} |
1096 | 0 | else if (OBJECT_ARRAY_CLASS.isAssignableFrom(value.getClass())) |
1097 | |
{ |
1098 | 0 | return new ArrayDataModel((Object[]) value); |
1099 | |
} |
1100 | 0 | else if (value instanceof ResultSet) |
1101 | |
{ |
1102 | 0 | return new ResultSetDataModel((ResultSet) value); |
1103 | |
} |
1104 | 0 | else if (value instanceof Result) |
1105 | |
{ |
1106 | 0 | return new ResultDataModel((Result) value); |
1107 | |
} |
1108 | |
else |
1109 | |
{ |
1110 | 0 | return new ScalarDataModel(value); |
1111 | |
} |
1112 | |
} |
1113 | |
|
1114 | |
|
1115 | |
|
1116 | |
|
1117 | |
|
1118 | |
|
1119 | |
|
1120 | |
|
1121 | |
|
1122 | |
|
1123 | |
|
1124 | |
|
1125 | |
|
1126 | |
|
1127 | |
|
1128 | |
|
1129 | |
|
1130 | |
|
1131 | |
|
1132 | |
@JSFProperty |
1133 | |
public Object getValue() |
1134 | |
{ |
1135 | 0 | if (_value != null) |
1136 | |
{ |
1137 | 0 | return _value; |
1138 | |
} |
1139 | 0 | ValueExpression expression = getValueExpression("value"); |
1140 | 0 | if (expression != null) |
1141 | |
{ |
1142 | 0 | return expression.getValue(getFacesContext().getELContext()); |
1143 | |
} |
1144 | 0 | return null; |
1145 | |
} |
1146 | |
|
1147 | |
public void setValue(Object value) |
1148 | |
{ |
1149 | 0 | _value = value; |
1150 | 0 | _dataModelMap.clear(); |
1151 | 0 | _rowStates.clear(); |
1152 | 0 | _isValidChilds = true; |
1153 | 0 | } |
1154 | |
|
1155 | |
|
1156 | |
|
1157 | |
|
1158 | |
@JSFProperty |
1159 | |
public int getFirst() |
1160 | |
{ |
1161 | 0 | if (_firstSet) |
1162 | |
{ |
1163 | 0 | return _first; |
1164 | |
} |
1165 | 0 | ValueExpression expression = getValueExpression("first"); |
1166 | 0 | if (expression != null) |
1167 | |
{ |
1168 | 0 | return (Integer)expression.getValue(getFacesContext().getELContext()); |
1169 | |
} |
1170 | 0 | return 0; |
1171 | |
} |
1172 | |
|
1173 | |
public void setFirst(int first) |
1174 | |
{ |
1175 | 0 | if (first < 0) |
1176 | |
{ |
1177 | 0 | throw new IllegalArgumentException("Illegal value for first row: " + first); |
1178 | |
} |
1179 | 0 | _first = first; |
1180 | 0 | _firstSet=true; |
1181 | 0 | } |
1182 | |
|
1183 | |
|
1184 | |
|
1185 | |
|
1186 | |
|
1187 | |
|
1188 | |
|
1189 | |
|
1190 | |
@JSFProperty |
1191 | |
public int getRows() |
1192 | |
{ |
1193 | 0 | if (_rowsSet) |
1194 | |
{ |
1195 | 0 | return _rows; |
1196 | |
} |
1197 | 0 | ValueExpression expression = getValueExpression("rows"); |
1198 | 0 | if (expression != null) |
1199 | |
{ |
1200 | 0 | return (Integer)expression.getValue(getFacesContext().getELContext()); |
1201 | |
} |
1202 | 0 | return 0; |
1203 | |
} |
1204 | |
|
1205 | |
|
1206 | |
|
1207 | |
|
1208 | |
public void setRows(int rows) |
1209 | |
{ |
1210 | 0 | if (rows < 0) |
1211 | |
{ |
1212 | 0 | throw new IllegalArgumentException("rows: " + rows); |
1213 | |
} |
1214 | 0 | _rows = rows; |
1215 | 0 | _rowsSet = true; |
1216 | 0 | } |
1217 | |
|
1218 | |
|
1219 | |
|
1220 | |
|
1221 | |
|
1222 | |
|
1223 | |
|
1224 | |
|
1225 | |
|
1226 | |
|
1227 | |
|
1228 | |
@JSFProperty(literalOnly = true) |
1229 | |
public String getVar() |
1230 | |
{ |
1231 | 0 | return _var; |
1232 | |
} |
1233 | |
|
1234 | |
public void setVar(String var) |
1235 | |
{ |
1236 | 0 | this._var = var; |
1237 | 0 | } |
1238 | |
|
1239 | |
|
1240 | |
@Override |
1241 | |
public Object saveState(FacesContext facesContext) |
1242 | |
{ |
1243 | 0 | Object[] values = new Object[7]; |
1244 | 0 | values[0] = super.saveState(facesContext); |
1245 | 0 | values[1] = _value; |
1246 | 0 | values[2] = _var; |
1247 | 0 | values[3] = _rows; |
1248 | 0 | values[4] = _rowsSet; |
1249 | 0 | values[5] = _first; |
1250 | 0 | values[6] = _firstSet; |
1251 | |
|
1252 | 0 | return values; |
1253 | |
} |
1254 | |
|
1255 | |
@Override |
1256 | |
public void restoreState(FacesContext facesContext, Object state) |
1257 | |
{ |
1258 | 0 | Object[] values = (Object[])state; |
1259 | 0 | super.restoreState(facesContext,values[0]); |
1260 | 0 | _value = values[1]; |
1261 | 0 | _var = (String)values[2]; |
1262 | 0 | _rows = (Integer)values[3]; |
1263 | 0 | _rowsSet = (Boolean)values[4]; |
1264 | 0 | _first = (Integer)values[5]; |
1265 | 0 | _firstSet = (Boolean)values[6]; |
1266 | 0 | } |
1267 | |
|
1268 | |
@Override |
1269 | |
public String getFamily() |
1270 | |
{ |
1271 | 0 | return COMPONENT_FAMILY; |
1272 | |
} |
1273 | |
} |