Method from javax.faces.component.UIViewRoot Detail: |
public void addComponentResource(FacesContext context,
UIComponent componentResource) {
addComponentResource(context, componentResource, null);
}
|
public void addComponentResource(FacesContext context,
UIComponent componentResource,
String target) {
final Map< String,Object > attributes = componentResource.getAttributes();
// look for a target in the component attribute set if arg is not set.
if (target == null) {
target = (String) attributes.get("target");
}
if (target == null) {
target = "head";
}
List< UIComponent > facetChildren = getComponentResources(context,
target,
true);
String id = componentResource.getId();
if (id != null) {
for (UIComponent c : facetChildren) {
if (id.equals(c.getId())) {
facetChildren.remove(c);
}
}
}
// add the resource to the facet
facetChildren.add(componentResource);
}
Add argument component ,
which is assumed to represent a resource instance, as a resource
to this view. A resource instance is rendered by a resource
Renderer , as described in the Standard HTML
RenderKit.
The component must be added using the following
algorithm:
If the target argument is null ,
look for a target attribute on the
component . If there is no target
attribute, set target to be the default value
head
Call #getComponentResources to obtain the child
list for the given target.
If the component ID of componentResource matches the
the ID of a resource that has allready been added, remove the old
resource.
Add the component resource to the
list.
|
public void addPhaseListener(PhaseListener newPhaseListener) {
getStateHelper().add(PropertyKeys.phaseListeners, newPhaseListener);
}
|
public void broadcastEvents(FacesContext context,
PhaseId phaseId) {
if (null == events) {
// no events have been queued
return;
}
boolean hasMoreAnyPhaseEvents;
boolean hasMoreCurrentPhaseEvents;
List< FacesEvent > eventsForPhaseId =
events.get(PhaseId.ANY_PHASE.getOrdinal());
// keep iterating till we have no more events to broadcast.
// This is necessary for events that cause other events to be
// queued. PENDING(edburns): here's where we'd put in a check
// to prevent infinite event queueing.
do {
// broadcast the ANY_PHASE events first
if (null != eventsForPhaseId) {
// We cannot use an Iterator because we will get
// ConcurrentModificationException errors, so fake it
while (!eventsForPhaseId.isEmpty()) {
FacesEvent event =
eventsForPhaseId.get(0);
UIComponent source = event.getComponent();
UIComponent compositeParent = null;
try {
if (!UIComponent.isCompositeComponent(source)) {
compositeParent = UIComponent.getCompositeComponentParent(source);
}
if (compositeParent != null) {
compositeParent.pushComponentToEL(context, null);
}
source.pushComponentToEL(context, null);
source.broadcast(event);
} catch (AbortProcessingException e) {
context.getApplication().publishEvent(context,
ExceptionQueuedEvent.class,
new ExceptionQueuedEventContext(context,
e,
source,
phaseId));
}
finally {
source.popComponentFromEL(context);
if (compositeParent != null) {
compositeParent.popComponentFromEL(context);
}
}
eventsForPhaseId.remove(0); // Stay at current position
}
}
// then broadcast the events for this phase.
if (null != (eventsForPhaseId = events.get(phaseId.getOrdinal()))) {
// We cannot use an Iterator because we will get
// ConcurrentModificationException errors, so fake it
while (!eventsForPhaseId.isEmpty()) {
FacesEvent event = eventsForPhaseId.get(0);
UIComponent source = event.getComponent();
UIComponent compositeParent = null;
try {
if (!UIComponent.isCompositeComponent(source)) {
compositeParent = getCompositeComponentParent(source);
}
if (compositeParent != null) {
compositeParent.pushComponentToEL(context, null);
}
source.pushComponentToEL(context, null);
source.broadcast(event);
} catch (AbortProcessingException ape) {
// A "return" here would abort remaining events too
context.getApplication().publishEvent(context,
ExceptionQueuedEvent.class,
new ExceptionQueuedEventContext(context,
ape,
source,
phaseId));
}
finally {
source.popComponentFromEL(context);
if (compositeParent != null) {
compositeParent.popComponentFromEL(context);
}
}
eventsForPhaseId.remove(0); // Stay at current position
}
}
// true if we have any more ANY_PHASE events
hasMoreAnyPhaseEvents =
(null != (eventsForPhaseId =
events.get(PhaseId.ANY_PHASE.getOrdinal()))) &&
!eventsForPhaseId.isEmpty();
// true if we have any more events for the argument phaseId
hasMoreCurrentPhaseEvents =
(null != events.get(phaseId.getOrdinal())) &&
!events.get(phaseId.getOrdinal()).isEmpty();
} while (hasMoreAnyPhaseEvents || hasMoreCurrentPhaseEvents);
}
Broadcast any events that have been
queued. First broadcast events that have been queued for PhaseId#ANY_PHASE . Then broadcast ane events that have been
queued for the current phase. In both cases, UIComponent#pushComponentToEL must be called before the event is
broadcast, and UIComponent#popComponentFromEL must be
called after the return from the broadcast, even in the case of
an exception.
|
public String createUniqueId() {
return createUniqueId(getFacesContext(), null);
}
Generate an identifier for a component. The identifier will
be prefixed with UNIQUE_ID_PREFIX, and will be unique within
this UIViewRoot.
|
public String createUniqueId(FacesContext context,
String seed) {
if (seed != null) {
return UIViewRoot.UNIQUE_ID_PREFIX + seed;
} else {
Integer i = (Integer) getStateHelper().get(PropertyKeys.lastId);
int lastId = ((i != null) ? i : 0);
getStateHelper().put(PropertyKeys.lastId, ++lastId);
return UIViewRoot.UNIQUE_ID_PREFIX + lastId;
}
}
Generate an identifier for a component. The identifier
will be prefixed with UNIQUE_ID_PREFIX, and will be unique
within this UIViewRoot. Optionally, a unique seed value can
be supplied by component creators which should be
included in the generated unique id.
|
public void encodeBegin(FacesContext context) throws IOException {
initState();
notifyBefore(context, PhaseId.RENDER_RESPONSE);
if (!skipPhase) {
super.encodeBegin(context);
}
}
|
public void encodeChildren(FacesContext context) throws IOException {
if (context.getPartialViewContext().isAjaxRequest()) {
context.getPartialViewContext().processPartial(PhaseId.RENDER_RESPONSE);
} else {
super.encodeChildren(context);
}
}
|
public void encodeEnd(FacesContext context) throws IOException {
super.encodeEnd(context);
encodeViewParameters(context);
notifyAfter(context, PhaseId.RENDER_RESPONSE);
}
|
public MethodExpression getAfterPhaseListener() {
return (MethodExpression) getStateHelper().get(PropertyKeys.afterPhase);
}
|
public MethodExpression getBeforePhaseListener() {
return (MethodExpression) getStateHelper().get(PropertyKeys.beforePhase);
}
|
public List<UIComponent> getComponentResources(FacesContext context,
String target) {
if (target == null) {
throw new NullPointerException();
}
List< UIComponent > resources = getComponentResources(context,
target,
false);
return ((resources != null)
? resources
: Collections.< UIComponent >emptyList());
}
Return an unmodifiable
List of UIComponent s for the provided
target agrument. Each component in the
List is assumed to represent a resource
instance.
The default implementation must use an algorithm equivalent to the
the following.
- Locate the facet for the
component by calling getFacet() using
target as the argument.
- If the facet is not found, create the facet by calling
context.getApplication().createComponent()
using javax.faces.Panel as the argument
- Set the
id of the facet to be target
- Add the facet to the facets
Map using target as the key
- return the children of the facet
|
public String getFamily() {
return (COMPONENT_FAMILY);
}
|
public Locale getLocale() {
Object result = getStateHelper().eval(PropertyKeys.locale);
if (result != null) {
Locale locale = null;
if (result instanceof Locale) {
locale = (Locale) result;
} else if (result instanceof String) {
locale = getLocaleFromString((String) result);
}
return locale;
} else {
FacesContext context = getFacesContext();
return context.getApplication().getViewHandler().calculateLocale(context);
}
}
Return the Locale to be used in localizing the
response being created for this view.
Algorithm:
If we have a locale ivar, return it. If we have
a value expression for "locale", get its value. If the value is
null , return the result of calling javax.faces.application.ViewHandler#calculateLocale . If the
value is an instance of java.util.Locale return it.
If the value is a String, convert it to a
java.util.Locale and return it. If there is no
value expression for "locale", return the result of calling javax.faces.application.ViewHandler#calculateLocale .
|
public List<PhaseListener> getPhaseListeners() {
//noinspection unchecked
List< PhaseListener > result = (List< PhaseListener >)
getStateHelper().get(PropertyKeys.phaseListeners);
return ((result != null)
? Collections.unmodifiableList(result)
: Collections.unmodifiableList(Collections.< PhaseListener >emptyList()));
}
|
public String getRenderKitId() {
return (String) getStateHelper().eval(PropertyKeys.renderKitId);
}
|
public boolean getRendersChildren() {
boolean value = super.getRendersChildren();
FacesContext context = FacesContext.getCurrentInstance();
if (context.getPartialViewContext().isAjaxRequest()) {
value = true;
}
return value;
}
|
public String getViewId() {
return (String) getStateHelper().get(PropertyKeys.viewId);
}
|
public List<SystemEventListener> getViewListenersForEventClass(Class<SystemEvent> systemEvent) {
if (systemEvent == null) {
throw new NullPointerException();
}
if (viewListeners != null) {
return viewListeners.get(systemEvent);
}
return null;
}
Return the
SystemEventListener instances registered on this
UIComponent instance that are interested in events
of type eventClass .
|
public Map<String, Object> getViewMap() {
return getViewMap(true);
}
This implementation simply calls through to #getViewMap(boolean) , passing true as the argument, and
returns the result.
|
public Map<String, Object> getViewMap(boolean create) {
if (create && viewScope == null) {
viewScope = new ViewMap(getFacesContext().getApplication().getProjectStage());
getFacesContext().getApplication()
.publishEvent(getFacesContext(),
PostConstructViewMapEvent.class,
this);
}
return viewScope;
}
Returns a Map that acts as the
interface to the data store that is the "view scope", or, if this
instance does not have such a Map and the
create argument is true , creates one and
returns it. This map must be instantiated lazily and cached for return
from subsequent calls to this method on this UIViewRoot
instance. javax.faces.application.Application#publishEvent must
be called, passing PostConstructViewMapEvent .class as the
first argument and this UIViewRoot instance as the second
argument.
The returned Map must be implemented such that calling
clear() on the Map causes javax.faces.application.Application#publishEvent to be
called, passing PreDestroyViewMapEvent .class
as the first argument and this UIViewRoot instance
as the second argument.
See FacesContext#setViewRoot for the specification of when the
clear() method must be called.
|
public boolean isInView() {
return true;
}
|
public void processApplication(FacesContext context) {
initState();
notifyBefore(context, PhaseId.INVOKE_APPLICATION);
try {
if (!skipPhase) {
// NOTE - no tree walk is performed; this is a UIViewRoot-only operation
broadcastEvents(context, PhaseId.INVOKE_APPLICATION);
}
} finally {
clearFacesEvents(context);
notifyAfter(context, PhaseId.INVOKE_APPLICATION);
}
}
|
public void processDecodes(FacesContext context) {
initState();
notifyBefore(context, PhaseId.APPLY_REQUEST_VALUES);
try {
if (!skipPhase) {
if (context.getPartialViewContext().isPartialRequest() &&
!context.getPartialViewContext().isExecuteAll()) {
context.getPartialViewContext().processPartial(PhaseId.APPLY_REQUEST_VALUES);
} else {
super.processDecodes(context);
}
broadcastEvents(context, PhaseId.APPLY_REQUEST_VALUES);
}
} finally {
clearFacesEvents(context);
notifyAfter(context, PhaseId.APPLY_REQUEST_VALUES);
}
}
|
public void processRestoreState(FacesContext context,
Object state) {
try {
// hack to work around older state managers that may not set the
// view root early enough
if (context.getViewRoot() == null) {
context.setViewRoot(this);
}
super.processRestoreState(context, state);
} finally {
final PostRestoreStateEvent event = new PostRestoreStateEvent(this);
try {
this.visitTree(VisitContext.createVisitContext(context),
new VisitCallback() {
public VisitResult visit(VisitContext context, UIComponent target) {
event.setComponent(target);
target.processEvent(event);
//noinspection ReturnInsideFinallyBlock
return VisitResult.ACCEPT;
}
});
} catch (AbortProcessingException e) {
context.getApplication().publishEvent(context,
ExceptionQueuedEvent.class,
new ExceptionQueuedEventContext(context,
e,
null,
PhaseId.RESTORE_VIEW));
}
}
}
|
public void processUpdates(FacesContext context) {
initState();
notifyBefore(context, PhaseId.UPDATE_MODEL_VALUES);
try {
if (!skipPhase) {
if (context.getPartialViewContext().isPartialRequest() &&
!context.getPartialViewContext().isExecuteAll()) {
context.getPartialViewContext().processPartial(PhaseId.UPDATE_MODEL_VALUES);
} else {
super.processUpdates(context);
}
broadcastEvents(context, PhaseId.UPDATE_MODEL_VALUES);
}
} finally {
clearFacesEvents(context);
notifyAfter(context, PhaseId.UPDATE_MODEL_VALUES);
}
}
|
public void processValidators(FacesContext context) {
initState();
notifyBefore(context, PhaseId.PROCESS_VALIDATIONS);
try {
if (!skipPhase) {
if (context.getPartialViewContext().isPartialRequest() &&
!context.getPartialViewContext().isExecuteAll()) {
context.getPartialViewContext().processPartial(PhaseId.PROCESS_VALIDATIONS);
} else {
super.processValidators(context);
}
broadcastEvents(context, PhaseId.PROCESS_VALIDATIONS);
}
} finally {
clearFacesEvents(context);
notifyAfter(context, PhaseId.PROCESS_VALIDATIONS);
}
}
|
public void queueEvent(FacesEvent event) {
if (event == null) {
throw new NullPointerException();
}
// We are a UIViewRoot, so no need to check for the ISE
if (events == null) {
int len = PhaseId.VALUES.size();
List< List< FacesEvent > > events = new ArrayList< List< FacesEvent > >(len);
for (int i = 0; i < len; i++) {
events.add(new ArrayList< FacesEvent >(5));
}
this.events = events;
}
events.get(event.getPhaseId().getOrdinal()).add(event);
}
|
public void removeComponentResource(FacesContext context,
UIComponent componentResource) {
removeComponentResource(context, componentResource, null);
}
Remove argument component ,
which is assumed to represent a resource instance, as a resource
to this view.
|
public void removeComponentResource(FacesContext context,
UIComponent componentResource,
String target) {
final Map< String,Object > attributes = componentResource.getAttributes();
// look for a target in the component attribute set if arg is not set.
if (target == null) {
target = (String) attributes.get("target");
}
if (target == null) {
target = "head";
}
List< UIComponent > facetChildren = getComponentResources(context,
target,
false);
if (facetChildren != null) {
facetChildren.remove(componentResource);
}
}
Remove argument component ,
which is assumed to represent a resource instance, as a resource
to this view. A resource instance is rendered by a resource
Renderer , as described in the Standard HTML
RenderKit.
The component must be removed using the following algorithm:
- If the
target argument is null , look for a target
attribute on the component .
If there is no target attribute, set target to be the default value head
- Call #getComponentResources to obtain the child list for the
given target.
- Remove the
component resource from the child list.
|
public void removePhaseListener(PhaseListener toRemove) {
getStateHelper().remove(PropertyKeys.phaseListeners, toRemove);
}
If the argument toRemove is in the list of PhaseListener s for this instance, it must be removed.
|
public void restoreState(FacesContext context,
Object state) {
if (context == null) {
throw new NullPointerException();
}
if (state == null) {
return;
}
values = (Object[]) state;
super.restoreState(context, values[0]);
//noinspection unchecked
viewScope = (Map< String,Object >) restoreAttachedState(context, values[1]);
}
|
public Object saveState(FacesContext context) {
if (context == null) {
throw new NullPointerException();
}
if (values == null) {
values = new Object[2];
}
values[0] = super.saveState(context);
values[1] = saveAttachedState(context, viewScope);
return (values);
}
|
public void setAfterPhaseListener(MethodExpression newAfterPhase) {
getStateHelper().put(PropertyKeys.afterPhase, newAfterPhase);
}
Allow an arbitrary
method to be called for the "afterPhase" event as the UIViewRoot
runs through its lifecycle. This method will be called for all
phases including PhaseId#RESTORE_VIEW . Unlike a true PhaseListener , this approach doesn't allow for only receiving
PhaseEvent s for a given phase. The method
must conform to the signature of PhaseListener#afterPhase .
|
public void setBeforePhaseListener(MethodExpression newBeforePhase) {
getStateHelper().put(PropertyKeys.beforePhase, newBeforePhase);
}
Allow an arbitrary
method to be called for the "beforePhase" event as the UIViewRoot
runs through its lifecycle. This method will be called for all
phases except PhaseId#RESTORE_VIEW . Unlike a true
PhaseListener , this approach doesn't allow for only
receiving PhaseEvent s for a given phase. The
method must conform to the signature of PhaseListener#beforePhase .
|
public void setInView(boolean isInView) {
// no-op
}
|
public void setLocale(Locale locale) {
getStateHelper().put(PropertyKeys.locale, locale);
// Make sure to appraise the EL of this switch in Locale.
FacesContext.getCurrentInstance().getELContext().setLocale(locale);
}
|
public void setRenderKitId(String renderKitId) {
getStateHelper().put(PropertyKeys.renderKitId, renderKitId);
}
Set the render kit identifier of the javax.faces.render.RenderKit
associated with this view. This method may be called at any time
between the end of Apply Request Values phase of the
request processing lifecycle (i.e. when events are being broadcast)
and the beginning of the Render Response phase.
|
public void setViewId(String viewId) {
getStateHelper().put(PropertyKeys.viewId, viewId);
}
|
public void subscribeToViewEvent(Class<SystemEvent> systemEvent,
SystemEventListener listener) {
if (systemEvent == null) {
throw new NullPointerException();
}
if (listener == null) {
throw new NullPointerException();
}
if (viewListeners == null) {
viewListeners = new HashMap< Class< ? extends SystemEvent >, List< SystemEventListener > >(4, 1.0f);
}
List< SystemEventListener > listeners = viewListeners.get(systemEvent);
if (listeners == null) {
listeners = new ArrayList< SystemEventListener >(2);
viewListeners.put(systemEvent, listeners);
}
listeners.add(listener);
}
Install the listener instance
referenced by argument listener into the
UIViewRoot as a listener for events of type
systemEventClass .
Note that installed listeners are not maintained as part of the
UIViewRoot 's state.
|
public void unsubscribeFromViewEvent(Class<SystemEvent> systemEvent,
SystemEventListener listener) {
if (systemEvent == null) {
throw new NullPointerException();
}
if (listener == null) {
throw new NullPointerException();
}
if (viewListeners != null) {
List< SystemEventListener > listeners = viewListeners.get(systemEvent);
if (listeners != null) {
listeners.remove(listener);
}
}
}
Remove the listener instance
referenced by argument listener from the
UIViewRoot as a listener for events of type
systemEventClass .
|