- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListener,SystemEventListenerHolder,EventListener
- Direct Known Subclasses:
Highlight
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.
- Author:
- Bauke Scholtz
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.script.OnloadScript".Fields inherited from class org.omnifaces.component.script.ScriptFamily
COMPONENT_FAMILYFields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidencodeBegin(FacesContext context) If the current request is not an ajax request with partial rendering, then encode begin.voidencodeEnd(FacesContext context) If the current request is not an ajax request with partial rendering, then encode end.booleanisListenerForSource(Object source) voidprocessEvent(ComponentSystemEvent event) Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent), and if the event is aPostRestoreStateEvent, then subscribe this component toPreRenderViewEvent, which will invokeprocessEvent(SystemEvent).voidprocessEvent(SystemEvent event) If the event is aPreRenderViewEvent, and this component is rendered, and the current request is an ajax request with partial rendering, then encode the children asAjax.oncomplete(String...).Methods inherited from class org.omnifaces.component.script.ScriptFamily
getFamily, getRendersChildren, moveToBodyMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeAll, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getPassThroughAttributes, getRenderer, getRendererType, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, visitTreeMethods inherited from class jakarta.faces.component.UIComponent
getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent
-
Field Details
-
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.script.OnloadScript".- See Also:
-
-
Constructor Details
-
OnloadScript
public OnloadScript()
-
-
Method Details
-
processEvent
Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent), and if the event is aPostRestoreStateEvent, then subscribe this component toPreRenderViewEvent, which will invokeprocessEvent(SystemEvent).- Specified by:
processEventin interfaceComponentSystemEventListener- Overrides:
processEventin classUIComponent
-
isListenerForSource
- Specified by:
isListenerForSourcein interfaceSystemEventListener
-
processEvent
If the event is aPreRenderViewEvent, and this component is rendered, and the current request is an ajax request with partial rendering, then encode the children asAjax.oncomplete(String...).- Specified by:
processEventin interfaceSystemEventListener
-
encodeBegin
If the current request is not an ajax request with partial rendering, then encode begin.- Overrides:
encodeBeginin classScriptFamily- Throws:
IOException
-
encodeEnd
If the current request is not an ajax request with partial rendering, then encode end.- Overrides:
encodeEndin classScriptFamily- Throws:
IOException
-