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.util.ArrayList; |
23 | |
import java.util.Arrays; |
24 | |
import java.util.Collection; |
25 | |
import java.util.Collections; |
26 | |
import java.util.HashMap; |
27 | |
import java.util.Iterator; |
28 | |
import java.util.LinkedList; |
29 | |
import java.util.List; |
30 | |
import java.util.Locale; |
31 | |
import java.util.Map; |
32 | |
import java.util.logging.Level; |
33 | |
import java.util.logging.Logger; |
34 | |
|
35 | |
import javax.el.MethodExpression; |
36 | |
import javax.el.ValueExpression; |
37 | |
import javax.faces.FactoryFinder; |
38 | |
import javax.faces.application.ProjectStage; |
39 | |
import javax.faces.component.visit.VisitCallback; |
40 | |
import javax.faces.component.visit.VisitContext; |
41 | |
import javax.faces.component.visit.VisitResult; |
42 | |
import javax.faces.context.FacesContext; |
43 | |
import javax.faces.context.PartialViewContext; |
44 | |
import javax.faces.event.AbortProcessingException; |
45 | |
import javax.faces.event.ExceptionQueuedEvent; |
46 | |
import javax.faces.event.ExceptionQueuedEventContext; |
47 | |
import javax.faces.event.FacesEvent; |
48 | |
import javax.faces.event.PhaseEvent; |
49 | |
import javax.faces.event.PhaseId; |
50 | |
import javax.faces.event.PhaseListener; |
51 | |
import javax.faces.event.PostConstructViewMapEvent; |
52 | |
import javax.faces.event.PreDestroyViewMapEvent; |
53 | |
import javax.faces.event.SystemEvent; |
54 | |
import javax.faces.event.SystemEventListener; |
55 | |
import javax.faces.lifecycle.Lifecycle; |
56 | |
import javax.faces.lifecycle.LifecycleFactory; |
57 | |
import javax.faces.view.ViewDeclarationLanguage; |
58 | |
import javax.faces.view.ViewMetadata; |
59 | |
import javax.faces.webapp.FacesServlet; |
60 | |
|
61 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent; |
62 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty; |
63 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 2 | @JSFComponent(name = "f:view", bodyContent = "JSP", tagClass = "org.apache.myfaces.taglib.core.ViewTag") |
76 | |
@JSFJspProperty(name = "binding", returnType = "java.lang.String", tagExcluded = true) |
77 | 0 | public class UIViewRoot extends UIComponentBase implements UniqueIdVendor |
78 | |
{ |
79 | |
public static final String COMPONENT_FAMILY = "javax.faces.ViewRoot"; |
80 | |
public static final String COMPONENT_TYPE = "javax.faces.ViewRoot"; |
81 | |
public static final String METADATA_FACET_NAME = "javax_faces_metadata"; |
82 | |
public static final String UNIQUE_ID_PREFIX = "j_id"; |
83 | |
public static final String VIEW_PARAMETERS_KEY = "javax.faces.component.VIEW_PARAMETERS_KEY"; |
84 | |
|
85 | 568 | private transient Logger logger = null; |
86 | |
|
87 | 2 | private static final PhaseProcessor APPLY_REQUEST_VALUES_PROCESSOR = new ApplyRequestValuesPhaseProcessor(); |
88 | 2 | private static final PhaseProcessor PROCESS_VALIDATORS_PROCESSOR = new ProcessValidatorPhaseProcessor(); |
89 | 2 | private static final PhaseProcessor UPDATE_MODEL_PROCESSOR = new UpdateModelPhaseProcessor(); |
90 | |
|
91 | 2 | private static final VisitCallback RESET_VALUES_CALLBACK = new ResetValuesCallback(); |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
private static final Class<?> VIEW_SCOPE_PROXY_MAP_CLASS; |
99 | |
|
100 | |
static |
101 | |
{ |
102 | 2 | Class<?> viewMapClass = null; |
103 | |
try |
104 | |
{ |
105 | 2 | viewMapClass = _ClassUtils.classForName( |
106 | |
"org.apache.myfaces.view.ViewScopeProxyMap"); |
107 | |
} |
108 | 2 | catch (Exception e) |
109 | |
{ |
110 | |
|
111 | 0 | } |
112 | 2 | VIEW_SCOPE_PROXY_MAP_CLASS = viewMapClass; |
113 | 2 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
private List<FacesEvent> _events; |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
private Map<String, Object> _viewScope; |
131 | 568 | private transient boolean _restoreViewScopeStateCalled = false; |
132 | |
|
133 | 568 | private transient Lifecycle _lifecycle = null; |
134 | |
|
135 | |
private HashMap<Class<? extends SystemEvent>, List<SystemEventListener>> _systemEventListeners; |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
private transient Map<PhaseId, boolean[]> listenerSuccessMap; |
141 | |
|
142 | |
private static final String JAVAX_FACES_LOCATION_PREFIX = "javax_faces_location_"; |
143 | |
private static final String JAVAX_FACES_LOCATION_HEAD = "javax_faces_location_head"; |
144 | |
private static final String JAVAX_FACES_LOCATION_BODY = "javax_faces_location_body"; |
145 | |
private static final String JAVAX_FACES_LOCATION_FORM = "javax_faces_location_form"; |
146 | |
|
147 | |
private static final String SKIP_VIEW_MAP_SAVE_STATE = "oam.viewPool.SKIP_VIEW_MAP_SAVE_STATE"; |
148 | |
|
149 | 568 | private transient int _resetSaveStateMode = 0; |
150 | |
private transient boolean _resourceDependencyUniqueId; |
151 | |
private transient Map<String,Object> _attributesMap; |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public UIViewRoot() |
157 | 568 | { |
158 | 568 | setRendererType(null); |
159 | 568 | } |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public void addComponentResource(FacesContext context, UIComponent componentResource) |
165 | |
{ |
166 | 0 | addComponentResource(context, componentResource, null); |
167 | 0 | } |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void addComponentResource(FacesContext context, UIComponent componentResource, String target) |
173 | |
{ |
174 | |
|
175 | 0 | if (target == null) |
176 | |
{ |
177 | |
|
178 | 0 | target = (String)componentResource.getAttributes().get("target"); |
179 | |
|
180 | |
|
181 | 0 | if (target == null) |
182 | |
{ |
183 | 0 | target = "head"; |
184 | |
} |
185 | |
} |
186 | |
|
187 | |
|
188 | 0 | List<UIComponent> componentResources = _getComponentResources(context, target); |
189 | |
|
190 | |
|
191 | |
|
192 | 0 | String componentId = componentResource.getId(); |
193 | |
|
194 | 0 | if (componentId == null) |
195 | |
{ |
196 | |
|
197 | |
|
198 | 0 | componentId = createUniqueId(context, null); |
199 | 0 | componentResource.setId(componentId); |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | 0 | boolean alreadyAdded = false; |
211 | |
|
212 | |
|
213 | 0 | if (componentResource.isInView()) |
214 | |
{ |
215 | 0 | if (componentResource.getParent() != null && |
216 | |
componentResource.getParent().getId() != null && |
217 | |
componentResource.getParent().getId().equals(JAVAX_FACES_LOCATION_PREFIX + target)) |
218 | |
{ |
219 | |
|
220 | |
|
221 | |
|
222 | 0 | alreadyAdded = true; |
223 | |
} |
224 | 0 | else if (componentId != null) |
225 | |
{ |
226 | 0 | for(Iterator<UIComponent> it = componentResources.iterator(); it.hasNext();) |
227 | |
{ |
228 | 0 | UIComponent component = it.next(); |
229 | 0 | if(componentId.equals(component.getId()) && componentResource != component) |
230 | |
{ |
231 | 0 | if (!component.isCachedFacesContext()) |
232 | |
{ |
233 | |
try |
234 | |
{ |
235 | 0 | component.setCachedFacesContext(context); |
236 | 0 | it.remove(); |
237 | |
} |
238 | |
finally |
239 | |
{ |
240 | 0 | component.setCachedFacesContext(null); |
241 | 0 | } |
242 | |
} |
243 | |
else |
244 | |
{ |
245 | 0 | it.remove(); |
246 | |
} |
247 | |
} |
248 | 0 | else if (componentResource == component) |
249 | |
{ |
250 | 0 | alreadyAdded = true; |
251 | |
} |
252 | 0 | } |
253 | |
} |
254 | |
} |
255 | 0 | else if (componentId != null) |
256 | |
{ |
257 | 0 | for(Iterator<UIComponent> it = componentResources.iterator(); it.hasNext();) |
258 | |
{ |
259 | 0 | UIComponent component = it.next(); |
260 | 0 | if(componentId.equals(component.getId()) && componentResource != component) |
261 | |
{ |
262 | 0 | if (!component.isCachedFacesContext()) |
263 | |
{ |
264 | |
try |
265 | |
{ |
266 | 0 | component.setCachedFacesContext(context); |
267 | 0 | it.remove(); |
268 | |
} |
269 | |
finally |
270 | |
{ |
271 | 0 | component.setCachedFacesContext(null); |
272 | 0 | } |
273 | |
} |
274 | |
else |
275 | |
{ |
276 | 0 | it.remove(); |
277 | |
} |
278 | |
} |
279 | 0 | else if (componentResource == component) |
280 | |
{ |
281 | 0 | alreadyAdded = true; |
282 | |
} |
283 | 0 | } |
284 | |
} |
285 | |
|
286 | |
|
287 | 0 | if (!alreadyAdded) |
288 | |
{ |
289 | 0 | if (!componentResource.isCachedFacesContext()) |
290 | |
{ |
291 | |
try |
292 | |
{ |
293 | 0 | componentResource.setCachedFacesContext(context); |
294 | 0 | componentResources.add(componentResource); |
295 | |
} |
296 | |
finally |
297 | |
{ |
298 | 0 | componentResource.setCachedFacesContext(context); |
299 | 0 | } |
300 | |
} |
301 | |
else |
302 | |
{ |
303 | 0 | componentResources.add(componentResource); |
304 | |
} |
305 | |
} |
306 | 0 | } |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
public void addPhaseListener(PhaseListener phaseListener) |
312 | |
{ |
313 | 12 | if (phaseListener == null) |
314 | |
{ |
315 | 0 | throw new NullPointerException("phaseListener"); |
316 | |
} |
317 | |
|
318 | 12 | getStateHelper().add(PropertyKeys.phaseListeners, phaseListener); |
319 | 12 | } |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public void broadcastEvents(FacesContext context, PhaseId phaseId) |
325 | |
{ |
326 | 8 | if (_events == null) |
327 | |
{ |
328 | 4 | return; |
329 | |
} |
330 | |
|
331 | 4 | Events events = _getEvents(phaseId); |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | 4 | int loops = 0; |
349 | 4 | int maxLoops = 15; |
350 | 4 | Collection<FacesEvent> eventsAborted = new LinkedList<FacesEvent>(); |
351 | |
do |
352 | |
{ |
353 | |
|
354 | 32 | boolean noUnexpectedException = _broadcastAll(context, events.getAnyPhase(), eventsAborted); |
355 | 32 | if (!noUnexpectedException) |
356 | |
{ |
357 | 0 | return; |
358 | |
} |
359 | 32 | List<FacesEvent> eventsOnPhase = events.getOnPhase(); |
360 | 32 | if (!eventsAborted.isEmpty()) |
361 | |
{ |
362 | 0 | eventsOnPhase.removeAll(eventsAborted); |
363 | 0 | eventsAborted.clear(); |
364 | |
} |
365 | 32 | noUnexpectedException = _broadcastAll(context, eventsOnPhase, eventsAborted); |
366 | 32 | if (!noUnexpectedException) |
367 | |
{ |
368 | 0 | return; |
369 | |
} |
370 | |
|
371 | 32 | events = _getEvents(phaseId); |
372 | 32 | loops++; |
373 | |
|
374 | 32 | } while (events.hasMoreEvents() && loops < maxLoops); |
375 | |
|
376 | 4 | if (loops == maxLoops && events.hasMoreEvents()) |
377 | |
{ |
378 | |
|
379 | 2 | boolean production = getFacesContext().isProjectStage(ProjectStage.Production); |
380 | 2 | Level level = production ? Level.FINE : Level.WARNING; |
381 | 2 | if (_getLogger().isLoggable(level)) |
382 | |
{ |
383 | 2 | List<String> name = new ArrayList<String>(events.getAnyPhase().size() + events.getOnPhase().size()); |
384 | 2 | for (FacesEvent facesEvent : events.getAnyPhase()) |
385 | |
{ |
386 | 0 | String clientId = facesEvent.getComponent().getClientId(getFacesContext()); |
387 | 0 | name.add(clientId); |
388 | 0 | } |
389 | 2 | for (FacesEvent facesEvent : events.getOnPhase()) |
390 | |
{ |
391 | 4 | String clientId = facesEvent.getComponent().getClientId(getFacesContext()); |
392 | 4 | name.add(clientId); |
393 | 4 | } |
394 | 2 | _getLogger().log(level, |
395 | |
"Event broadcating for PhaseId {0} at UIViewRoot {1} reaches maximal limit, please check " + |
396 | |
"listeners for infinite recursion. Component id: {2}", |
397 | |
new Object [] {phaseId, getViewId(), name}); |
398 | |
} |
399 | |
} |
400 | 4 | } |
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
public String createUniqueId() |
407 | |
{ |
408 | 20106 | return createUniqueId(getFacesContext(), null); |
409 | |
} |
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
public String createUniqueId(FacesContext context, String seed) |
418 | |
{ |
419 | |
|
420 | |
|
421 | |
|
422 | 20108 | if(seed==null) |
423 | |
{ |
424 | 20108 | if (isResourceDependencyUniqueId()) |
425 | |
{ |
426 | 0 | Integer uniqueIdCounter = (Integer) getStateHelper().get( |
427 | |
PropertyKeys.resourceDependencyUniqueIdCounter); |
428 | 0 | uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter; |
429 | 0 | getStateHelper().put(PropertyKeys.resourceDependencyUniqueIdCounter, (uniqueIdCounter+1)); |
430 | 0 | if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_RD_IDS_SIZE) |
431 | |
{ |
432 | 0 | StringBuilder bld = _getSharedStringBuilder(context); |
433 | 0 | return bld.append(UNIQUE_ID_PREFIX).append( |
434 | |
_ComponentUtils.RD_ID_PREFIX).append(uniqueIdCounter).toString(); |
435 | |
} |
436 | |
else |
437 | |
{ |
438 | 0 | return _ComponentUtils.UNIQUE_COMPONENT_RD_IDS[uniqueIdCounter]; |
439 | |
} |
440 | |
} |
441 | |
else |
442 | |
{ |
443 | 20108 | Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter); |
444 | 20108 | uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter; |
445 | 20108 | getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1)); |
446 | 20108 | if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_V_IDS_SIZE) |
447 | |
{ |
448 | 19900 | StringBuilder bld = _getSharedStringBuilder(context); |
449 | 19900 | return bld.append(UNIQUE_ID_PREFIX).append( |
450 | |
_ComponentUtils.V_ID_PREFIX).append(uniqueIdCounter).toString(); |
451 | |
} |
452 | |
else |
453 | |
{ |
454 | 208 | return _ComponentUtils.UNIQUE_COMPONENT_V_IDS[uniqueIdCounter]; |
455 | |
} |
456 | |
} |
457 | |
} |
458 | |
|
459 | |
|
460 | |
else |
461 | |
{ |
462 | 0 | StringBuilder bld = _getSharedStringBuilder(context); |
463 | 0 | return bld.append(UNIQUE_ID_PREFIX).append(seed).toString(); |
464 | |
} |
465 | |
} |
466 | |
|
467 | |
@Override |
468 | |
public void encodeBegin(FacesContext context) throws IOException |
469 | |
{ |
470 | 0 | checkNull(context, "context"); |
471 | |
|
472 | 0 | boolean skipPhase = false; |
473 | |
|
474 | |
try |
475 | |
{ |
476 | 0 | skipPhase = notifyListeners(context, PhaseId.RENDER_RESPONSE, getBeforePhaseListener(), true); |
477 | |
} |
478 | 0 | catch (Exception e) |
479 | |
{ |
480 | |
|
481 | 0 | _getLogger().log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e); |
482 | 0 | } |
483 | |
|
484 | 0 | if (!skipPhase) |
485 | |
{ |
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | 0 | super.encodeBegin(context); |
492 | |
} |
493 | |
else |
494 | |
{ |
495 | 0 | pushComponentToEL(context, this); |
496 | |
} |
497 | 0 | } |
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
@Override |
503 | |
public void encodeChildren(FacesContext context) throws IOException |
504 | |
{ |
505 | 0 | if (context.getResponseComplete()) |
506 | |
{ |
507 | 0 | return; |
508 | |
} |
509 | 0 | PartialViewContext pContext = context.getPartialViewContext(); |
510 | |
|
511 | |
|
512 | 0 | if (pContext.isAjaxRequest()) |
513 | |
{ |
514 | |
|
515 | |
|
516 | 0 | pContext.processPartial(PhaseId.RENDER_RESPONSE); |
517 | |
} |
518 | |
else |
519 | |
{ |
520 | |
|
521 | |
|
522 | 0 | super.encodeChildren(context); |
523 | |
} |
524 | 0 | } |
525 | |
|
526 | |
@Override |
527 | |
public void encodeEnd(FacesContext context) throws IOException |
528 | |
{ |
529 | 0 | checkNull(context, "context"); |
530 | |
|
531 | 0 | if (!context.getResponseComplete()) |
532 | |
{ |
533 | 0 | super.encodeEnd(context); |
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | 0 | PartialViewContext partialContext = context.getPartialViewContext(); |
540 | 0 | if (!partialContext.isAjaxRequest()) |
541 | |
{ |
542 | 0 | ViewDeclarationLanguage vdl |
543 | |
= context.getApplication().getViewHandler().getViewDeclarationLanguage(context, getViewId()); |
544 | 0 | if (vdl != null) |
545 | |
{ |
546 | |
|
547 | |
|
548 | |
|
549 | 0 | ViewMetadata metadata = null; |
550 | |
try |
551 | |
{ |
552 | 0 | metadata = vdl.getViewMetadata(context, getViewId()); |
553 | |
} |
554 | 0 | catch(UnsupportedOperationException e) |
555 | |
{ |
556 | 0 | _getLogger().log(Level.SEVERE, "Exception while obtaining the view metadata: " + |
557 | |
e.getMessage(), e); |
558 | 0 | } |
559 | |
|
560 | 0 | if (metadata != null) |
561 | |
{ |
562 | |
try |
563 | |
{ |
564 | 0 | Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(this); |
565 | 0 | if(!viewParams.isEmpty()) |
566 | |
{ |
567 | |
|
568 | 0 | for(UIViewParameter param : viewParams) |
569 | |
{ |
570 | 0 | param.encodeAll(context); |
571 | 0 | } |
572 | |
} |
573 | |
} |
574 | 0 | catch(UnsupportedOperationException e) |
575 | |
{ |
576 | |
|
577 | |
|
578 | 0 | } |
579 | |
} |
580 | |
} |
581 | |
} |
582 | |
} |
583 | |
|
584 | |
try |
585 | |
{ |
586 | 0 | notifyListeners(context, PhaseId.RENDER_RESPONSE, getAfterPhaseListener(), false); |
587 | |
} |
588 | 0 | catch (Exception e) |
589 | |
{ |
590 | |
|
591 | 0 | _getLogger().log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e); |
592 | 0 | } |
593 | 0 | } |
594 | |
|
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
|
601 | |
@JSFProperty(returnSignature = "void", methodSignature = "javax.faces.event.PhaseEvent", |
602 | |
jspName = "afterPhase", stateHolder=true) |
603 | |
public MethodExpression getAfterPhaseListener() |
604 | |
{ |
605 | 0 | return (MethodExpression) getStateHelper().eval(PropertyKeys.afterPhaseListener); |
606 | |
} |
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | |
@JSFProperty(returnSignature = "void", methodSignature = "javax.faces.event.PhaseEvent", |
615 | |
jspName = "beforePhase", stateHolder=true) |
616 | |
public MethodExpression getBeforePhaseListener() |
617 | |
{ |
618 | 0 | return (MethodExpression) getStateHelper().eval(PropertyKeys.beforePhaseListener); |
619 | |
} |
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
public List<UIComponent> getComponentResources(FacesContext context, String target) |
625 | |
{ |
626 | 0 | if (target == null) |
627 | |
{ |
628 | 0 | throw new NullPointerException("target"); |
629 | |
} |
630 | |
|
631 | 0 | UIComponent facet = getFacet(target); |
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | 0 | if (facet != null) |
656 | |
{ |
657 | 0 | if (facet.getChildCount() > 0) |
658 | |
{ |
659 | 0 | return Collections.unmodifiableList(facet.getChildren()); |
660 | |
} |
661 | |
else |
662 | |
{ |
663 | 0 | return Collections.<UIComponent>emptyList(); |
664 | |
} |
665 | |
} |
666 | 0 | return Collections.<UIComponent>emptyList(); |
667 | |
} |
668 | |
|
669 | |
private List<UIComponent> _getComponentResources(FacesContext context, String target) |
670 | |
{ |
671 | |
|
672 | 0 | UIComponent facet = getFacet(target); |
673 | |
|
674 | |
|
675 | 0 | if (facet == null) |
676 | |
{ |
677 | |
|
678 | |
|
679 | 0 | facet = context.getApplication().createComponent(context, |
680 | |
"javax.faces.ComponentResourceContainer", null); |
681 | |
|
682 | |
|
683 | 0 | if (target.equals("head")) |
684 | |
{ |
685 | 0 | facet.setId(JAVAX_FACES_LOCATION_HEAD); |
686 | |
} |
687 | 0 | else if (target.equals("body")) |
688 | |
{ |
689 | 0 | facet.setId(JAVAX_FACES_LOCATION_BODY); |
690 | |
} |
691 | 0 | else if (target.equals("form")) |
692 | |
{ |
693 | 0 | facet.setId(JAVAX_FACES_LOCATION_FORM); |
694 | |
} |
695 | |
else |
696 | |
{ |
697 | 0 | facet.setId(JAVAX_FACES_LOCATION_PREFIX + target); |
698 | |
} |
699 | |
|
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
|
706 | |
|
707 | |
|
708 | |
|
709 | |
|
710 | 0 | getFacets().put(target, facet); |
711 | |
} |
712 | 0 | return facet.getChildren(); |
713 | |
} |
714 | |
|
715 | |
@Override |
716 | |
public String getFamily() |
717 | |
{ |
718 | 0 | return COMPONENT_FAMILY; |
719 | |
} |
720 | |
|
721 | |
|
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
|
727 | |
@JSFProperty |
728 | |
public Locale getLocale() |
729 | |
{ |
730 | 68 | Object locale = getStateHelper().get(PropertyKeys.locale); |
731 | 68 | if (locale != null) |
732 | |
{ |
733 | 52 | return (Locale)locale; |
734 | |
} |
735 | 16 | ValueExpression expression = getValueExpression(PropertyKeys.locale.toString()); |
736 | 16 | if (expression != null) |
737 | |
{ |
738 | 0 | Object veLocale = expression.getValue(getFacesContext().getELContext()); |
739 | 0 | if (veLocale instanceof Locale) |
740 | |
{ |
741 | 0 | return (Locale) veLocale; |
742 | |
} |
743 | |
else |
744 | |
{ |
745 | 0 | return (Locale) _LocaleUtils.toLocale(veLocale.toString()); |
746 | |
} |
747 | |
} |
748 | |
else |
749 | |
{ |
750 | 16 | locale = getFacesContext().getApplication().getViewHandler().calculateLocale(getFacesContext()); |
751 | |
|
752 | 16 | if (locale instanceof Locale) |
753 | |
{ |
754 | 14 | return (Locale)locale; |
755 | |
} |
756 | 2 | else if (locale instanceof String) |
757 | |
{ |
758 | 0 | return _LocaleUtils.toLocale((String)locale); |
759 | |
} |
760 | |
} |
761 | |
|
762 | 2 | return getFacesContext().getApplication().getViewHandler().calculateLocale(getFacesContext()); |
763 | |
} |
764 | |
|
765 | |
|
766 | |
|
767 | |
|
768 | |
public List<PhaseListener> getPhaseListeners() |
769 | |
{ |
770 | 24 | List<PhaseListener> listeners = (List<PhaseListener>) getStateHelper().get(PropertyKeys.phaseListeners); |
771 | 24 | if (listeners == null) |
772 | |
{ |
773 | 8 | listeners = Collections.emptyList(); |
774 | |
} |
775 | |
else |
776 | |
{ |
777 | 16 | listeners = Collections.unmodifiableList(listeners); |
778 | |
} |
779 | |
|
780 | 24 | return listeners; |
781 | |
} |
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
@JSFProperty |
787 | |
public String getRenderKitId() |
788 | |
{ |
789 | 270 | return (String) getStateHelper().eval(PropertyKeys.renderKitId); |
790 | |
} |
791 | |
|
792 | |
|
793 | |
|
794 | |
|
795 | |
@Override |
796 | |
public boolean getRendersChildren() |
797 | |
{ |
798 | |
|
799 | |
|
800 | 0 | PartialViewContext context = getFacesContext().getPartialViewContext(); |
801 | |
|
802 | 0 | return (context.isAjaxRequest()) ? true : super.getRendersChildren(); |
803 | |
} |
804 | |
|
805 | |
|
806 | |
|
807 | |
|
808 | |
|
809 | |
|
810 | |
|
811 | |
@JSFProperty(tagExcluded = true) |
812 | |
public String getViewId() |
813 | |
{ |
814 | 72 | return (String) getStateHelper().get(PropertyKeys.viewId); |
815 | |
} |
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
public Map<String, Object> getViewMap() |
821 | |
{ |
822 | 0 | return this.getViewMap(true); |
823 | |
} |
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
public Map<String, Object> getViewMap(boolean create) |
829 | |
{ |
830 | 0 | if (_viewScope == null && create) |
831 | |
{ |
832 | 0 | if (VIEW_SCOPE_PROXY_MAP_CLASS != null) |
833 | |
{ |
834 | 0 | _viewScope = (Map<String, Object>) |
835 | |
_ClassUtils.newInstance(VIEW_SCOPE_PROXY_MAP_CLASS); |
836 | |
} |
837 | |
else |
838 | |
{ |
839 | |
|
840 | 0 | _viewScope = new ViewScope(); |
841 | |
} |
842 | 0 | FacesContext facesContext = getFacesContext(); |
843 | 0 | if (facesContext != null) |
844 | |
{ |
845 | 0 | facesContext.getApplication().publishEvent(facesContext, PostConstructViewMapEvent.class, this); |
846 | |
} |
847 | |
} |
848 | |
|
849 | 0 | return _viewScope; |
850 | |
} |
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
@Override |
856 | |
public boolean isInView() |
857 | |
{ |
858 | 64 | return true; |
859 | |
} |
860 | |
|
861 | |
public void processApplication(final FacesContext context) |
862 | |
{ |
863 | 0 | checkNull(context, "context"); |
864 | 0 | _process(context, PhaseId.INVOKE_APPLICATION, null); |
865 | 0 | } |
866 | |
|
867 | |
@Override |
868 | |
public void processDecodes(FacesContext context) |
869 | |
{ |
870 | 0 | checkNull(context, "context"); |
871 | 0 | _process(context, PhaseId.APPLY_REQUEST_VALUES, APPLY_REQUEST_VALUES_PROCESSOR); |
872 | 0 | } |
873 | |
|
874 | |
|
875 | |
|
876 | |
|
877 | |
@Override |
878 | |
public void processRestoreState(FacesContext context, Object state) |
879 | |
{ |
880 | |
|
881 | |
|
882 | |
try |
883 | |
{ |
884 | 0 | super.processRestoreState(context, state); |
885 | |
} |
886 | |
finally |
887 | |
{ |
888 | |
|
889 | 0 | broadcastEvents(context, PhaseId.RESTORE_VIEW); |
890 | |
|
891 | |
|
892 | 0 | } |
893 | 0 | } |
894 | |
|
895 | |
@Override |
896 | |
public void queueEvent(FacesEvent event) |
897 | |
{ |
898 | 64 | checkNull(event, "event"); |
899 | 64 | if (_events == null) |
900 | |
{ |
901 | 4 | _events = new ArrayList<FacesEvent>(); |
902 | |
} |
903 | |
|
904 | 64 | _events.add(event); |
905 | 64 | } |
906 | |
|
907 | |
@Override |
908 | |
public void processValidators(FacesContext context) |
909 | |
{ |
910 | 0 | checkNull(context, "context"); |
911 | 0 | _process(context, PhaseId.PROCESS_VALIDATIONS, PROCESS_VALIDATORS_PROCESSOR); |
912 | 0 | } |
913 | |
|
914 | |
@Override |
915 | |
public void processUpdates(FacesContext context) |
916 | |
{ |
917 | 0 | checkNull(context, "context"); |
918 | 0 | _process(context, PhaseId.UPDATE_MODEL_VALUES, UPDATE_MODEL_PROCESSOR); |
919 | 0 | } |
920 | |
|
921 | |
public void setLocale(Locale locale) |
922 | |
{ |
923 | 48 | getStateHelper().put(PropertyKeys.locale, locale ); |
924 | 48 | } |
925 | |
|
926 | |
|
927 | |
|
928 | |
|
929 | |
|
930 | |
|
931 | |
|
932 | |
|
933 | |
|
934 | |
|
935 | |
|
936 | |
|
937 | |
|
938 | |
|
939 | |
|
940 | |
|
941 | |
|
942 | |
private boolean notifyListeners(FacesContext context, PhaseId phaseId, MethodExpression listener, |
943 | |
boolean beforePhase) |
944 | |
{ |
945 | 0 | List<PhaseListener> phaseListeners = (List<PhaseListener>) getStateHelper().get(PropertyKeys.phaseListeners); |
946 | |
|
947 | 0 | boolean listenerCalled = false; |
948 | 0 | if (listener != null || (phaseListeners != null && !phaseListeners.isEmpty())) |
949 | |
{ |
950 | |
|
951 | |
|
952 | 0 | int listenerCount = (phaseListeners != null ? phaseListeners.size() + 1 : 1); |
953 | |
|
954 | |
boolean[] beforePhaseSuccess; |
955 | 0 | if (beforePhase) |
956 | |
{ |
957 | 0 | beforePhaseSuccess = new boolean[listenerCount]; |
958 | 0 | _getListenerSuccessMap().put(phaseId, beforePhaseSuccess); |
959 | |
} |
960 | |
else |
961 | |
{ |
962 | |
|
963 | 0 | beforePhaseSuccess = _getListenerSuccessMap().get(phaseId); |
964 | 0 | if (beforePhaseSuccess == null) |
965 | |
{ |
966 | |
|
967 | 0 | beforePhaseSuccess = new boolean[listenerCount]; |
968 | 0 | Arrays.fill(beforePhaseSuccess, true); |
969 | |
} |
970 | |
} |
971 | |
|
972 | 0 | PhaseEvent event = createEvent(context, phaseId); |
973 | |
|
974 | |
|
975 | |
|
976 | 0 | if (listener != null && (beforePhase || beforePhaseSuccess[0])) |
977 | |
{ |
978 | 0 | listenerCalled = true; |
979 | |
try |
980 | |
{ |
981 | 0 | listener.invoke(context.getELContext(), new Object[] { event }); |
982 | 0 | beforePhaseSuccess[0] = true; |
983 | |
} |
984 | 0 | catch (Throwable t) |
985 | |
{ |
986 | 0 | beforePhaseSuccess[0] = false; |
987 | 0 | _getLogger().log(Level.SEVERE, "An Exception occured while processing " + |
988 | |
listener.getExpressionString() + |
989 | |
" in Phase " + phaseId, t); |
990 | 0 | if (beforePhase) |
991 | |
{ |
992 | 0 | return context.getResponseComplete() || |
993 | |
(context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId)); |
994 | |
} |
995 | 0 | } |
996 | |
} |
997 | 0 | else if (beforePhase) |
998 | |
{ |
999 | |
|
1000 | 0 | beforePhaseSuccess[0] = true; |
1001 | |
} |
1002 | |
|
1003 | 0 | if (phaseListeners != null && !phaseListeners.isEmpty()) |
1004 | |
{ |
1005 | 0 | if (beforePhase) |
1006 | |
{ |
1007 | |
|
1008 | 0 | for (int i = 0; i < beforePhaseSuccess.length - 1; i++) |
1009 | |
{ |
1010 | |
PhaseListener phaseListener; |
1011 | |
try |
1012 | |
{ |
1013 | 0 | phaseListener = phaseListeners.get(i); |
1014 | |
} |
1015 | 0 | catch (IndexOutOfBoundsException e) |
1016 | |
{ |
1017 | |
|
1018 | |
|
1019 | 0 | throw new IllegalStateException("A PhaseListener must not remove " + |
1020 | |
"PhaseListeners from UIViewRoot."); |
1021 | 0 | } |
1022 | 0 | PhaseId listenerPhaseId = phaseListener.getPhaseId(); |
1023 | 0 | if (phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId)) |
1024 | |
{ |
1025 | 0 | listenerCalled = true; |
1026 | |
try |
1027 | |
{ |
1028 | 0 | phaseListener.beforePhase(event); |
1029 | 0 | beforePhaseSuccess[i + 1] = true; |
1030 | |
} |
1031 | 0 | catch (Throwable t) |
1032 | |
{ |
1033 | 0 | beforePhaseSuccess[i + 1] = false; |
1034 | 0 | _getLogger().log(Level.SEVERE, "An Exception occured while processing the " + |
1035 | |
"beforePhase method of PhaseListener " + phaseListener + |
1036 | |
" in Phase " + phaseId, t); |
1037 | 0 | return context.getResponseComplete() || |
1038 | |
(context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId)); |
1039 | 0 | } |
1040 | |
} |
1041 | |
} |
1042 | |
} |
1043 | |
else |
1044 | |
{ |
1045 | |
|
1046 | |
|
1047 | 0 | for (int i = beforePhaseSuccess.length - 1; i > 0; i--) |
1048 | |
{ |
1049 | |
PhaseListener phaseListener; |
1050 | |
try |
1051 | |
{ |
1052 | 0 | phaseListener = phaseListeners.get(i - 1); |
1053 | |
} |
1054 | 0 | catch (IndexOutOfBoundsException e) |
1055 | |
{ |
1056 | |
|
1057 | |
|
1058 | 0 | throw new IllegalStateException("A PhaseListener must not remove " + |
1059 | |
"PhaseListeners from UIViewRoot."); |
1060 | 0 | } |
1061 | 0 | PhaseId listenerPhaseId = phaseListener.getPhaseId(); |
1062 | 0 | if ((phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId)) |
1063 | |
&& beforePhaseSuccess[i]) |
1064 | |
{ |
1065 | 0 | listenerCalled = true; |
1066 | |
try |
1067 | |
{ |
1068 | 0 | phaseListener.afterPhase(event); |
1069 | |
} |
1070 | 0 | catch (Throwable t) |
1071 | |
{ |
1072 | 0 | logger.log(Level.SEVERE, "An Exception occured while processing the " + |
1073 | |
"afterPhase method of PhaseListener " + phaseListener + |
1074 | |
" in Phase " + phaseId, t); |
1075 | 0 | } |
1076 | |
} |
1077 | |
} |
1078 | |
} |
1079 | |
} |
1080 | |
} |
1081 | |
|
1082 | |
|
1083 | |
|
1084 | |
|
1085 | |
|
1086 | |
|
1087 | |
|
1088 | 0 | if (listenerCalled) |
1089 | |
{ |
1090 | 0 | if (beforePhase) |
1091 | |
{ |
1092 | 0 | return context.getResponseComplete() || |
1093 | |
(context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId)); |
1094 | |
} |
1095 | |
else |
1096 | |
{ |
1097 | 0 | return context.getResponseComplete() || context.getRenderResponse(); |
1098 | |
} |
1099 | |
} |
1100 | |
else |
1101 | |
{ |
1102 | 0 | if (beforePhase) |
1103 | |
{ |
1104 | 0 | if (PhaseId.RENDER_RESPONSE.equals(phaseId)) |
1105 | |
{ |
1106 | 0 | return context.getResponseComplete(); |
1107 | |
} |
1108 | |
else |
1109 | |
{ |
1110 | |
|
1111 | 0 | return false; |
1112 | |
} |
1113 | |
} |
1114 | |
else |
1115 | |
{ |
1116 | |
|
1117 | 0 | return context.getResponseComplete() || context.getRenderResponse(); |
1118 | |
} |
1119 | |
} |
1120 | |
} |
1121 | |
|
1122 | |
private PhaseEvent createEvent(FacesContext context, PhaseId phaseId) |
1123 | |
{ |
1124 | 0 | if (_lifecycle == null) |
1125 | |
{ |
1126 | 0 | LifecycleFactory factory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
1127 | 0 | String id = context.getExternalContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR); |
1128 | 0 | if (id == null) |
1129 | |
{ |
1130 | 0 | id = LifecycleFactory.DEFAULT_LIFECYCLE; |
1131 | |
} |
1132 | 0 | _lifecycle = factory.getLifecycle(id); |
1133 | |
} |
1134 | 0 | return new PhaseEvent(context, phaseId, _lifecycle); |
1135 | |
} |
1136 | |
|
1137 | |
|
1138 | |
|
1139 | |
|
1140 | |
|
1141 | |
|
1142 | |
|
1143 | |
|
1144 | |
|
1145 | |
|
1146 | |
|
1147 | |
|
1148 | |
private boolean _broadcastAll(FacesContext context, |
1149 | |
List<? extends FacesEvent> events, |
1150 | |
Collection<FacesEvent> eventsAborted) |
1151 | |
{ |
1152 | 64 | assert events != null; |
1153 | |
|
1154 | 124 | for (int i = 0; i < events.size(); i++) |
1155 | |
{ |
1156 | 60 | FacesEvent event = events.get(i); |
1157 | 60 | UIComponent source = event.getComponent(); |
1158 | 60 | UIComponent compositeParent = UIComponent.getCompositeComponentParent(source); |
1159 | 60 | if (compositeParent != null) |
1160 | |
{ |
1161 | 0 | pushComponentToEL(context, compositeParent); |
1162 | |
} |
1163 | |
|
1164 | 60 | pushComponentToEL(context, source); |
1165 | |
|
1166 | |
try |
1167 | |
{ |
1168 | |
|
1169 | 60 | if (!source.isCachedFacesContext()) |
1170 | |
{ |
1171 | |
try |
1172 | |
{ |
1173 | 60 | source.setCachedFacesContext(context); |
1174 | 60 | source.broadcast(event); |
1175 | |
} |
1176 | |
finally |
1177 | |
{ |
1178 | 60 | source.setCachedFacesContext(null); |
1179 | 60 | } |
1180 | |
} |
1181 | |
else |
1182 | |
{ |
1183 | 0 | source.broadcast(event); |
1184 | |
} |
1185 | |
} |
1186 | 0 | catch (Exception e) |
1187 | |
{ |
1188 | |
|
1189 | 0 | Throwable cause = e; |
1190 | 0 | AbortProcessingException ape = null; |
1191 | |
do |
1192 | |
{ |
1193 | 0 | if (cause != null && cause instanceof AbortProcessingException) |
1194 | |
{ |
1195 | 0 | ape = (AbortProcessingException) cause; |
1196 | 0 | break; |
1197 | |
} |
1198 | 0 | cause = cause.getCause(); |
1199 | |
} |
1200 | 0 | while (cause != null); |
1201 | |
|
1202 | |
|
1203 | |
|
1204 | |
|
1205 | |
|
1206 | 0 | if (ape != null) |
1207 | |
{ |
1208 | 0 | e = ape; |
1209 | |
} |
1210 | 0 | ExceptionQueuedEventContext exceptionContext |
1211 | |
= new ExceptionQueuedEventContext(context, e, source, context.getCurrentPhaseId()); |
1212 | 0 | context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, exceptionContext); |
1213 | |
|
1214 | |
|
1215 | 0 | if (ape != null) |
1216 | |
{ |
1217 | |
|
1218 | 0 | eventsAborted.add(event); |
1219 | |
} |
1220 | |
else |
1221 | |
{ |
1222 | |
|
1223 | 0 | return false; |
1224 | |
} |
1225 | |
} |
1226 | |
finally |
1227 | |
{ |
1228 | |
|
1229 | 60 | source.popComponentFromEL(context); |
1230 | 60 | if (compositeParent != null) |
1231 | |
{ |
1232 | 0 | compositeParent.popComponentFromEL(context); |
1233 | |
} |
1234 | |
} |
1235 | |
} |
1236 | 64 | return true; |
1237 | |
} |
1238 | |
|
1239 | |
private void clearEvents() |
1240 | |
{ |
1241 | 0 | _events = null; |
1242 | 0 | } |
1243 | |
|
1244 | |
private void checkNull(Object value, String valueLabel) |
1245 | |
{ |
1246 | 242 | if (value == null) |
1247 | |
{ |
1248 | 0 | throw new NullPointerException(valueLabel + " is null"); |
1249 | |
} |
1250 | 242 | } |
1251 | |
|
1252 | |
public void setRenderKitId(String renderKitId) |
1253 | |
{ |
1254 | 524 | getStateHelper().put(PropertyKeys.renderKitId, renderKitId ); |
1255 | 524 | } |
1256 | |
|
1257 | |
|
1258 | |
|
1259 | |
|
1260 | |
|
1261 | |
|
1262 | |
|
1263 | |
|
1264 | |
@Override |
1265 | |
@JSFProperty(tagExcluded = true) |
1266 | |
public void setRendered(boolean state) |
1267 | |
{ |
1268 | |
|
1269 | 0 | super.setRendered(state); |
1270 | |
|
1271 | 0 | } |
1272 | |
|
1273 | |
@JSFProperty(tagExcluded=true) |
1274 | |
@Override |
1275 | |
public void setId(String id) |
1276 | |
{ |
1277 | 30 | super.setId(id); |
1278 | 30 | } |
1279 | |
|
1280 | |
|
1281 | |
|
1282 | |
|
1283 | |
@Override |
1284 | |
public void setInView(boolean isInView) |
1285 | |
{ |
1286 | |
|
1287 | 0 | } |
1288 | |
|
1289 | |
public void removeComponentResource(FacesContext context, UIComponent componentResource) |
1290 | |
{ |
1291 | 0 | removeComponentResource(context, componentResource, null); |
1292 | 0 | } |
1293 | |
|
1294 | |
public void removeComponentResource(FacesContext context, UIComponent componentResource, String target) |
1295 | |
{ |
1296 | |
|
1297 | 0 | if (target == null) |
1298 | |
{ |
1299 | |
|
1300 | 0 | target = (String)componentResource.getAttributes().get("target"); |
1301 | |
|
1302 | |
|
1303 | 0 | if (target == null) |
1304 | |
{ |
1305 | |
|
1306 | 0 | target = "head"; |
1307 | |
} |
1308 | |
} |
1309 | |
|
1310 | |
|
1311 | |
|
1312 | |
|
1313 | 0 | UIComponent facet = getFacet(target); |
1314 | 0 | if (facet != null) |
1315 | |
{ |
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
|
1320 | 0 | facet.getChildren().remove(componentResource); |
1321 | |
} |
1322 | 0 | } |
1323 | |
|
1324 | |
public void setViewId(String viewId) |
1325 | |
{ |
1326 | |
|
1327 | |
|
1328 | |
|
1329 | 520 | getStateHelper().put(PropertyKeys.viewId, viewId ); |
1330 | 520 | } |
1331 | |
|
1332 | |
|
1333 | |
|
1334 | |
|
1335 | |
public void removePhaseListener(PhaseListener phaseListener) |
1336 | |
{ |
1337 | 4 | if (phaseListener == null) |
1338 | |
{ |
1339 | 0 | return; |
1340 | |
} |
1341 | |
|
1342 | 4 | getStateHelper().remove(PropertyKeys.phaseListeners, phaseListener); |
1343 | 4 | } |
1344 | |
|
1345 | |
|
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
|
1350 | |
|
1351 | |
public void setBeforePhaseListener(MethodExpression beforePhaseListener) |
1352 | |
{ |
1353 | 0 | getStateHelper().put(PropertyKeys.beforePhaseListener, beforePhaseListener); |
1354 | 0 | } |
1355 | |
|
1356 | |
|
1357 | |
|
1358 | |
|
1359 | |
|
1360 | |
|
1361 | |
|
1362 | |
public void setAfterPhaseListener(MethodExpression afterPhaseListener) |
1363 | |
{ |
1364 | 0 | getStateHelper().put(PropertyKeys.afterPhaseListener, afterPhaseListener); |
1365 | 0 | } |
1366 | |
|
1367 | |
|
1368 | |
|
1369 | |
|
1370 | |
int getResetSaveStateMode() |
1371 | |
{ |
1372 | 484 | return _resetSaveStateMode; |
1373 | |
} |
1374 | |
|
1375 | |
|
1376 | |
|
1377 | |
|
1378 | |
void setResetSaveStateMode(int clearTransientMapOnSaveState) |
1379 | |
{ |
1380 | 0 | this._resetSaveStateMode = clearTransientMapOnSaveState; |
1381 | 0 | } |
1382 | |
|
1383 | |
@Override |
1384 | |
public Map<String, Object> getAttributes() |
1385 | |
{ |
1386 | 64 | if (_attributesMap == null) |
1387 | |
{ |
1388 | 6 | _attributesMap = new _ViewAttributeMap(this, super.getAttributes()); |
1389 | |
} |
1390 | 64 | return _attributesMap; |
1391 | |
} |
1392 | |
|
1393 | |
|
1394 | |
|
1395 | |
|
1396 | |
|
1397 | |
|
1398 | |
public void resetValues(FacesContext context, |
1399 | |
java.util.Collection<java.lang.String> clientIds) |
1400 | |
{ |
1401 | 0 | VisitContext visitContext = (VisitContext) VisitContext.createVisitContext( |
1402 | |
context, clientIds, null); |
1403 | 0 | this.visitTree(visitContext, RESET_VALUES_CALLBACK); |
1404 | 0 | } |
1405 | |
|
1406 | |
|
1407 | |
|
1408 | |
|
1409 | |
|
1410 | |
|
1411 | |
|
1412 | |
boolean isResourceDependencyUniqueId() |
1413 | |
{ |
1414 | 20108 | return _resourceDependencyUniqueId; |
1415 | |
} |
1416 | |
|
1417 | |
void setResourceDependencyUniqueId(boolean resourceDependencyUniqueId) |
1418 | |
{ |
1419 | 0 | this._resourceDependencyUniqueId = resourceDependencyUniqueId; |
1420 | 0 | } |
1421 | |
|
1422 | 18 | enum PropertyKeys |
1423 | |
{ |
1424 | 2 | afterPhaseListener |
1425 | 2 | , beforePhaseListener |
1426 | 2 | , phaseListeners |
1427 | 2 | , locale |
1428 | 2 | , renderKitId |
1429 | 2 | , viewId |
1430 | 2 | , uniqueIdCounter |
1431 | 2 | , resourceDependencyUniqueIdCounter |
1432 | |
} |
1433 | |
|
1434 | |
@Override |
1435 | |
public Object saveState(FacesContext facesContext) |
1436 | |
{ |
1437 | 8 | if (getResetSaveStateMode() == RESET_MODE_SOFT) |
1438 | |
{ |
1439 | |
|
1440 | 0 | if (_systemEventListeners != null) |
1441 | |
{ |
1442 | 0 | _systemEventListeners.clear(); |
1443 | |
} |
1444 | 0 | if (_events != null) |
1445 | |
{ |
1446 | 0 | _events.clear(); |
1447 | |
} |
1448 | 0 | if (listenerSuccessMap != null) |
1449 | |
{ |
1450 | 0 | listenerSuccessMap.clear(); |
1451 | |
} |
1452 | 0 | _restoreViewScopeStateCalled = false; |
1453 | |
} |
1454 | 8 | if (getResetSaveStateMode() == RESET_MODE_HARD) |
1455 | |
{ |
1456 | |
|
1457 | 0 | if (_systemEventListeners != null) |
1458 | |
{ |
1459 | 0 | _systemEventListeners.clear(); |
1460 | |
} |
1461 | 0 | if (_events != null) |
1462 | |
{ |
1463 | 0 | _events.clear(); |
1464 | |
} |
1465 | 0 | if (listenerSuccessMap != null) |
1466 | |
{ |
1467 | 0 | listenerSuccessMap.clear(); |
1468 | |
} |
1469 | 0 | if (_viewScope != null) |
1470 | |
{ |
1471 | 0 | if (VIEW_SCOPE_PROXY_MAP_CLASS.isInstance(_viewScope)) |
1472 | |
{ |
1473 | 0 | _viewScope = null; |
1474 | |
} |
1475 | |
else |
1476 | |
{ |
1477 | 0 | _viewScope.clear(); |
1478 | |
} |
1479 | |
} |
1480 | 0 | _restoreViewScopeStateCalled = false; |
1481 | |
} |
1482 | |
|
1483 | 8 | if (initialStateMarked()) |
1484 | |
{ |
1485 | 6 | Object parentSaved = super.saveState(facesContext); |
1486 | 6 | if (_viewScope != null && |
1487 | |
Boolean.TRUE.equals(facesContext.getAttributes().get( |
1488 | |
SKIP_VIEW_MAP_SAVE_STATE))) |
1489 | |
{ |
1490 | 0 | if (parentSaved == null) |
1491 | |
{ |
1492 | 0 | return null; |
1493 | |
} |
1494 | 0 | return new Object[]{parentSaved, null}; |
1495 | |
} |
1496 | |
|
1497 | 6 | if (parentSaved == null && _viewScope == null) |
1498 | |
{ |
1499 | |
|
1500 | 0 | return null; |
1501 | |
} |
1502 | 6 | else if (parentSaved == null && _viewScope != null && _viewScope.size() == 0 |
1503 | |
&& !(_viewScope instanceof StateHolder) ) |
1504 | |
{ |
1505 | |
|
1506 | 0 | return null; |
1507 | |
} |
1508 | |
|
1509 | 6 | Object[] values = new Object[2]; |
1510 | 6 | values[0] = parentSaved; |
1511 | 6 | values[1] = saveAttachedState(facesContext,_viewScope); |
1512 | 6 | return values; |
1513 | |
} |
1514 | |
else |
1515 | |
{ |
1516 | 2 | if (_viewScope != null && |
1517 | |
Boolean.TRUE.equals(facesContext.getAttributes().get( |
1518 | |
SKIP_VIEW_MAP_SAVE_STATE))) |
1519 | |
{ |
1520 | 0 | return new Object[]{super.saveState(facesContext), null}; |
1521 | |
} |
1522 | 2 | Object[] values = new Object[2]; |
1523 | 2 | values[0] = super.saveState(facesContext); |
1524 | 2 | values[1] = saveAttachedState(facesContext,_viewScope); |
1525 | 2 | return values; |
1526 | |
} |
1527 | |
} |
1528 | |
|
1529 | |
@SuppressWarnings("unchecked") |
1530 | |
@Override |
1531 | |
public void restoreState(FacesContext facesContext, Object state) |
1532 | |
{ |
1533 | 8 | if (state == null) |
1534 | |
{ |
1535 | 0 | return; |
1536 | |
} |
1537 | |
|
1538 | 8 | Object[] values = (Object[])state; |
1539 | 8 | super.restoreState(facesContext,values[0]); |
1540 | |
|
1541 | |
|
1542 | |
|
1543 | |
|
1544 | 8 | if (!_restoreViewScopeStateCalled) |
1545 | |
{ |
1546 | 8 | _viewScope = (Map<String, Object>) restoreAttachedState(facesContext, values[1]); |
1547 | |
} |
1548 | |
else |
1549 | |
{ |
1550 | 0 | _restoreViewScopeStateCalled = false; |
1551 | |
} |
1552 | 8 | } |
1553 | |
|
1554 | |
|
1555 | |
|
1556 | |
|
1557 | |
|
1558 | |
|
1559 | |
public void restoreViewScopeState(FacesContext facesContext, Object state) |
1560 | |
{ |
1561 | 0 | if (state == null) |
1562 | |
{ |
1563 | 0 | return; |
1564 | |
} |
1565 | |
|
1566 | |
|
1567 | |
|
1568 | |
|
1569 | |
|
1570 | |
|
1571 | |
|
1572 | |
|
1573 | 0 | Object[] values = (Object[])state; |
1574 | 0 | _viewScope = (Map<String, Object>) restoreAttachedState(facesContext, values[1]); |
1575 | 0 | _restoreViewScopeStateCalled = true; |
1576 | 0 | } |
1577 | |
|
1578 | |
public List<SystemEventListener> getViewListenersForEventClass(Class<? extends SystemEvent> systemEvent) |
1579 | |
{ |
1580 | 178 | checkNull (systemEvent, "systemEvent"); |
1581 | 178 | if (_systemEventListeners == null) |
1582 | |
{ |
1583 | 178 | return null; |
1584 | |
} |
1585 | 0 | return _systemEventListeners.get (systemEvent); |
1586 | |
} |
1587 | |
|
1588 | |
public void subscribeToViewEvent(Class<? extends SystemEvent> systemEvent, |
1589 | |
SystemEventListener listener) |
1590 | |
{ |
1591 | |
List<SystemEventListener> listeners; |
1592 | |
|
1593 | 0 | checkNull (systemEvent, "systemEvent"); |
1594 | 0 | checkNull (listener, "listener"); |
1595 | |
|
1596 | 0 | if (_systemEventListeners == null) |
1597 | |
{ |
1598 | 0 | _systemEventListeners = new HashMap<Class<? extends SystemEvent>, List<SystemEventListener>>(); |
1599 | |
} |
1600 | |
|
1601 | 0 | listeners = _systemEventListeners.get (systemEvent); |
1602 | |
|
1603 | 0 | if (listeners == null) |
1604 | |
{ |
1605 | 0 | listeners = new ArrayList<SystemEventListener>(); |
1606 | |
|
1607 | 0 | _systemEventListeners.put (systemEvent, listeners); |
1608 | |
} |
1609 | |
|
1610 | 0 | listeners.add (listener); |
1611 | 0 | } |
1612 | |
|
1613 | |
public void unsubscribeFromViewEvent(Class<? extends SystemEvent> systemEvent, |
1614 | |
SystemEventListener listener) |
1615 | |
{ |
1616 | |
List<SystemEventListener> listeners; |
1617 | |
|
1618 | 0 | checkNull (systemEvent, "systemEvent"); |
1619 | 0 | checkNull (listener, "listener"); |
1620 | |
|
1621 | 0 | if (_systemEventListeners == null) |
1622 | |
{ |
1623 | 0 | return; |
1624 | |
} |
1625 | |
|
1626 | 0 | listeners = _systemEventListeners.get (systemEvent); |
1627 | |
|
1628 | 0 | if (listeners != null) |
1629 | |
{ |
1630 | 0 | listeners.remove (listener); |
1631 | |
} |
1632 | 0 | } |
1633 | |
|
1634 | |
|
1635 | |
|
1636 | |
|
1637 | |
|
1638 | |
|
1639 | |
|
1640 | |
|
1641 | |
|
1642 | |
|
1643 | |
|
1644 | |
|
1645 | |
|
1646 | |
private boolean _process(FacesContext context, PhaseId phaseId, PhaseProcessor processor) |
1647 | |
{ |
1648 | 0 | RuntimeException processingException = null; |
1649 | |
try |
1650 | |
{ |
1651 | 0 | if (!notifyListeners(context, phaseId, getBeforePhaseListener(), true)) |
1652 | |
{ |
1653 | |
try |
1654 | |
{ |
1655 | 0 | if (processor != null) |
1656 | |
{ |
1657 | 0 | processor.process(context, this); |
1658 | |
} |
1659 | |
|
1660 | 0 | broadcastEvents(context, phaseId); |
1661 | |
} |
1662 | 0 | catch (RuntimeException re) |
1663 | |
{ |
1664 | |
|
1665 | |
|
1666 | 0 | processingException = re; |
1667 | 0 | } |
1668 | |
} |
1669 | |
} |
1670 | |
finally |
1671 | |
{ |
1672 | 0 | if (context.getRenderResponse() || context.getResponseComplete()) |
1673 | |
{ |
1674 | 0 | clearEvents(); |
1675 | |
} |
1676 | |
} |
1677 | |
|
1678 | 0 | boolean retVal = notifyListeners(context, phaseId, getAfterPhaseListener(), false); |
1679 | 0 | if (processingException == null) |
1680 | |
{ |
1681 | 0 | return retVal; |
1682 | |
} |
1683 | |
else |
1684 | |
{ |
1685 | 0 | throw processingException; |
1686 | |
} |
1687 | |
} |
1688 | |
|
1689 | |
private void _processDecodesDefault(FacesContext context) |
1690 | |
{ |
1691 | 0 | super.processDecodes(context); |
1692 | 0 | } |
1693 | |
|
1694 | |
private void _processUpdatesDefault(FacesContext context) |
1695 | |
{ |
1696 | 0 | super.processUpdates(context); |
1697 | 0 | } |
1698 | |
|
1699 | |
private void _processValidatorsDefault(FacesContext context) |
1700 | |
{ |
1701 | 0 | super.processValidators(context); |
1702 | 0 | } |
1703 | |
|
1704 | |
|
1705 | |
|
1706 | |
|
1707 | |
|
1708 | |
private Events _getEvents(PhaseId phaseId) |
1709 | |
{ |
1710 | |
|
1711 | 36 | int size = _events.size(); |
1712 | 36 | List<FacesEvent> anyPhase = new ArrayList<FacesEvent>(size); |
1713 | 36 | List<FacesEvent> onPhase = new ArrayList<FacesEvent>(size); |
1714 | |
|
1715 | 100 | for (int i = 0; i < size; i++) |
1716 | |
{ |
1717 | 64 | FacesEvent event = _events.get(i); |
1718 | 64 | if (event.getPhaseId().equals(PhaseId.ANY_PHASE)) |
1719 | |
{ |
1720 | 0 | anyPhase.add(event); |
1721 | 0 | _events.remove(i); |
1722 | 0 | size--; |
1723 | 0 | i--; |
1724 | |
} |
1725 | 64 | else if (event.getPhaseId().equals(phaseId)) |
1726 | |
{ |
1727 | 64 | onPhase.add(event); |
1728 | 64 | _events.remove(i); |
1729 | 64 | size--; |
1730 | 64 | i--; |
1731 | |
} |
1732 | |
} |
1733 | |
|
1734 | 36 | return new Events(anyPhase, onPhase); |
1735 | |
} |
1736 | |
|
1737 | |
private Logger _getLogger() |
1738 | |
{ |
1739 | 4 | if (logger == null) |
1740 | |
{ |
1741 | 2 | logger = Logger.getLogger(UIViewRoot.class.getName()); |
1742 | |
} |
1743 | 4 | return logger; |
1744 | |
} |
1745 | |
|
1746 | |
private Map<PhaseId, boolean[]> _getListenerSuccessMap() |
1747 | |
{ |
1748 | |
|
1749 | 0 | if (listenerSuccessMap == null) |
1750 | |
{ |
1751 | 0 | listenerSuccessMap = new HashMap<PhaseId, boolean[]>(); |
1752 | |
} |
1753 | 0 | return listenerSuccessMap; |
1754 | |
} |
1755 | |
|
1756 | |
private static interface PhaseProcessor |
1757 | |
{ |
1758 | |
public void process(FacesContext context, UIViewRoot root); |
1759 | |
} |
1760 | |
|
1761 | 4 | private static class ApplyRequestValuesPhaseProcessor implements PhaseProcessor |
1762 | |
{ |
1763 | |
public void process(FacesContext context, UIViewRoot root) |
1764 | |
{ |
1765 | 0 | PartialViewContext pvc = context.getPartialViewContext(); |
1766 | |
|
1767 | |
|
1768 | |
|
1769 | |
|
1770 | |
|
1771 | 0 | if (pvc.isPartialRequest() && !pvc.isExecuteAll()) |
1772 | |
{ |
1773 | 0 | pvc.processPartial(PhaseId.APPLY_REQUEST_VALUES); |
1774 | |
} |
1775 | |
|
1776 | |
|
1777 | |
|
1778 | |
|
1779 | |
|
1780 | |
else |
1781 | |
{ |
1782 | 0 | root._processDecodesDefault(context); |
1783 | |
} |
1784 | 0 | } |
1785 | |
} |
1786 | |
|
1787 | 4 | private static class ProcessValidatorPhaseProcessor implements PhaseProcessor |
1788 | |
{ |
1789 | |
public void process(FacesContext context, UIViewRoot root) |
1790 | |
{ |
1791 | 0 | PartialViewContext pvc = context.getPartialViewContext(); |
1792 | |
|
1793 | |
|
1794 | |
|
1795 | |
|
1796 | |
|
1797 | 0 | if (pvc.isPartialRequest() && !pvc.isExecuteAll()) |
1798 | |
{ |
1799 | 0 | pvc.processPartial(PhaseId.PROCESS_VALIDATIONS); |
1800 | |
} |
1801 | |
|
1802 | |
|
1803 | |
|
1804 | |
|
1805 | |
|
1806 | |
else |
1807 | |
{ |
1808 | 0 | root._processValidatorsDefault(context); |
1809 | |
} |
1810 | 0 | } |
1811 | |
} |
1812 | |
|
1813 | 4 | private static class UpdateModelPhaseProcessor implements PhaseProcessor |
1814 | |
{ |
1815 | |
public void process(FacesContext context, UIViewRoot root) |
1816 | |
{ |
1817 | 0 | PartialViewContext pvc = context.getPartialViewContext(); |
1818 | |
|
1819 | |
|
1820 | |
|
1821 | |
|
1822 | |
|
1823 | 0 | if (pvc.isPartialRequest() && !pvc.isExecuteAll()) |
1824 | |
{ |
1825 | 0 | pvc.processPartial(PhaseId.UPDATE_MODEL_VALUES); |
1826 | |
} |
1827 | |
|
1828 | |
|
1829 | |
|
1830 | |
|
1831 | |
|
1832 | |
else |
1833 | |
{ |
1834 | 0 | root._processUpdatesDefault(context); |
1835 | |
} |
1836 | 0 | } |
1837 | |
} |
1838 | |
|
1839 | |
|
1840 | |
|
1841 | |
|
1842 | |
|
1843 | |
|
1844 | |
|
1845 | |
|
1846 | |
|
1847 | |
|
1848 | |
|
1849 | |
|
1850 | |
|
1851 | |
|
1852 | |
|
1853 | |
|
1854 | |
|
1855 | |
|
1856 | |
|
1857 | |
|
1858 | |
|
1859 | |
|
1860 | |
|
1861 | |
|
1862 | |
|
1863 | |
|
1864 | |
|
1865 | |
|
1866 | |
|
1867 | |
|
1868 | |
|
1869 | |
|
1870 | |
@Deprecated |
1871 | 0 | private static class ViewScope extends HashMap<String, Object> |
1872 | |
{ |
1873 | |
|
1874 | |
private static final long serialVersionUID = -1088893802269478164L; |
1875 | |
|
1876 | |
@Override |
1877 | |
public void clear() |
1878 | |
{ |
1879 | |
|
1880 | |
|
1881 | |
|
1882 | |
|
1883 | |
|
1884 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
1885 | 0 | facesContext.getApplication().publishEvent(facesContext, |
1886 | |
PreDestroyViewMapEvent.class, facesContext.getViewRoot()); |
1887 | |
|
1888 | 0 | super.clear(); |
1889 | 0 | } |
1890 | |
|
1891 | |
} |
1892 | |
|
1893 | |
|
1894 | |
|
1895 | |
|
1896 | |
private static class Events |
1897 | |
{ |
1898 | |
|
1899 | |
private final List<FacesEvent> _anyPhase; |
1900 | |
|
1901 | |
private final List<FacesEvent> _onPhase; |
1902 | |
|
1903 | |
public Events(List<FacesEvent> anyPhase, List<FacesEvent> onPhase) |
1904 | |
{ |
1905 | 36 | super(); |
1906 | 36 | this._anyPhase = anyPhase; |
1907 | 36 | this._onPhase = onPhase; |
1908 | 36 | } |
1909 | |
|
1910 | |
public boolean hasMoreEvents() |
1911 | |
{ |
1912 | 34 | return (_anyPhase != null && _anyPhase.size() > 0) || (_onPhase != null && _onPhase.size() > 0); |
1913 | |
} |
1914 | |
|
1915 | |
public List<FacesEvent> getAnyPhase() |
1916 | |
{ |
1917 | 36 | return _anyPhase; |
1918 | |
} |
1919 | |
|
1920 | |
public List<FacesEvent> getOnPhase() |
1921 | |
{ |
1922 | 36 | return _onPhase; |
1923 | |
} |
1924 | |
} |
1925 | |
|
1926 | 4 | private static class ResetValuesCallback implements VisitCallback |
1927 | |
{ |
1928 | |
public VisitResult visit(VisitContext context, UIComponent target) |
1929 | |
{ |
1930 | 0 | if (target instanceof EditableValueHolder) |
1931 | |
{ |
1932 | 0 | ((EditableValueHolder)target).resetValue(); |
1933 | |
} |
1934 | 0 | return VisitResult.ACCEPT; |
1935 | |
} |
1936 | |
} |
1937 | |
} |