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_FAMILY
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, 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, moveToBody
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
public 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 ComponentSystemEventListener
processEvent
in class UIComponent
AbortProcessingException
public boolean isListenerForSource(Object source)
isListenerForSource
in interface SystemEventListener
public 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 SystemEventListener
AbortProcessingException
public void encodeBegin(FacesContext context) throws IOException
<script>
element.encodeBegin
in class UIComponentBase
IOException
public void encodeEnd(FacesContext context) throws IOException
<script>
element.encodeEnd
in class UIComponentBase
IOException
Copyright © 2012–2015 OmniFaces. All rights reserved.