public class OnloadScript extends ScriptFamily implements SystemEventListener
The <o:onloadScript is a component that extends the standard <h:outputScript>
which will be executed in the end of the HTML body (thus when all HTML elements are initialized in the HTML DOM tree)
and will re-execute its script body on every ajax request. This is particularly useful if you want to re-execute a
specific helper script to manipulate the HTML DOM tree, such as (re-)adding fancy tooltips, performing highlights,
etcetera, also after changes in the HTML DOM tree on ajax responses.
You can put it anywhere in the view, it will always be relocated to the end of body.
<o:onloadScript>alert('OnloadScript is invoked!');</o:onloadScript>
The <o:onloadScript> is implicitly relocated to the end of the <body>,
exactly like as <h:outputScript target="body"> does. So it's always executed when the entire
<body> is finished populating and thus you don't need a window.onload or a
$(document).ready() in there. Again, the difference with <h:outputScript target="body">
is that the <o:onloadScript> is also executed on every ajax request.
| Modifier and Type | Field and Description |
|---|---|
static String |
COMPONENT_TYPE
The standard component type.
|
COMPONENT_FAMILYBEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY| Constructor and Description |
|---|
OnloadScript() |
| Modifier and Type | Method and Description |
|---|---|
void |
encodeBegin(FacesContext context)
If this component is rendered, and the current request is not an ajax request with partial rendering, then start
the
<script> element. |
void |
encodeEnd(FacesContext context)
If this component is rendered, and the current request is not an ajax request with partial rendering, then end
the
<script> element. |
boolean |
isListenerForSource(Object source)
|
void |
processEvent(ComponentSystemEvent event)
Move this component to body using
ScriptFamily.moveToBody(ComponentSystemEvent, ScriptFamily), and if the event is a
PostRestoreStateEvent, then subscribe this component to PreRenderViewEvent, which will invoke
processEvent(SystemEvent). |
void |
processEvent(SystemEvent event)
If the event is a
PreRenderViewEvent, and this component is rendered, and the current request is an ajax
request with partial rendering, then encode the children as Ajax.oncomplete(String...). |
getFamily, getRendersChildren, moveToBodyaddClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBindingencodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent, visitTreepublic static final String COMPONENT_TYPE
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
ScriptFamily.moveToBody(ComponentSystemEvent, ScriptFamily), and if the event is a
PostRestoreStateEvent, then subscribe this component to PreRenderViewEvent, which will invoke
processEvent(SystemEvent).processEvent in interface ComponentSystemEventListenerprocessEvent in class UIComponentAbortProcessingExceptionpublic boolean isListenerForSource(Object source)
isListenerForSource in interface SystemEventListenerpublic void processEvent(SystemEvent event) throws AbortProcessingException
PreRenderViewEvent, and this component is rendered, and the current request is an ajax
request with partial rendering, then encode the children as Ajax.oncomplete(String...).processEvent in interface SystemEventListenerAbortProcessingExceptionpublic void encodeBegin(FacesContext context) throws IOException
<script> element.encodeBegin in class UIComponentBaseIOExceptionpublic void encodeEnd(FacesContext context) throws IOException
<script> element.encodeEnd in class UIComponentBaseIOExceptionCopyright © 2012–2016 OmniFaces. All rights reserved.