- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- org.omnifaces.component.script.ScriptFamily
-
- org.omnifaces.component.script.OnloadScript
-
- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListener,SystemEventListenerHolder,EventListener
- Direct Known Subclasses:
Highlight
public class OnloadScript extends ScriptFamily implements SystemEventListener
The
<o:onloadScriptis 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 awindow.onloador 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:
ScriptFamily
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMPONENT_TYPEThe component type, which is "org.omnifaces.component.script.OnloadScript".-
Fields inherited from class org.omnifaces.component.script.ScriptFamily
COMPONENT_FAMILY
-
Fields inherited from class jakarta.faces.component.UIComponent
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 Summary
Constructors Constructor Description OnloadScript()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencodeBegin(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, moveToBody
-
Methods inherited from class jakarta.faces.component.UIComponentBase
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
-
Methods inherited from class jakarta.faces.component.UIComponent
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
-
-
-
-
Field Detail
-
COMPONENT_TYPE
public static final String COMPONENT_TYPE
The component type, which is "org.omnifaces.component.script.OnloadScript".- See Also:
- Constant Field Values
-
-
Method Detail
-
processEvent
public void processEvent(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).- Specified by:
processEventin interfaceComponentSystemEventListener- Overrides:
processEventin classUIComponent
-
isListenerForSource
public boolean isListenerForSource(Object source)
- Specified by:
isListenerForSourcein interfaceSystemEventListener
-
processEvent
public void processEvent(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...).- Specified by:
processEventin interfaceSystemEventListener
-
encodeBegin
public void encodeBegin(FacesContext context) throws IOException
If the current request is not an ajax request with partial rendering, then encode begin.- Overrides:
encodeBeginin classScriptFamily- Throws:
IOException
-
encodeEnd
public void encodeEnd(FacesContext context) throws IOException
If the current request is not an ajax request with partial rendering, then encode end.- Overrides:
encodeEndin classScriptFamily- Throws:
IOException
-
-