public class OnloadScript extends ScriptFamily
<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>
Modifier and Type | Field and Description |
---|---|
static String |
COMPONENT_TYPE
The standard component type.
|
COMPONENT_FAMILY
BEANINFO_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 |
encodeChildren(FacesContext context)
If there are any children and the current request is an ajax request, then add the script body as a callback
function to
OmniFaces.Ajax.addRunOnceOnSuccess() . |
void |
processEvent(ComponentSystemEvent event)
If the event is a
PostAddToViewEvent , then relocate the component to end of body, so that we can make
sure that the script is executed after all HTML DOM elements are been created. |
getFamily, getRendersChildren
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeEnd, 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, setValueBinding
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, pushComponentToEL, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent, visitTree
public static final String COMPONENT_TYPE
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
PostAddToViewEvent
, then relocate the component to end of body, so that we can make
sure that the script is executed after all HTML DOM elements are been created. If the event is a
PostRestoreStateEvent
and the current request is an ajax request, then add the client ID of this
component to the collection of ajax render IDs, so that we can make sure that the script is executed on every
ajax response as well.processEvent
in interface ComponentSystemEventListener
processEvent
in class UIComponent
AbortProcessingException
public void encodeChildren(FacesContext context) throws IOException
OmniFaces.Ajax.addRunOnceOnSuccess()
. The entire <script>
element
is wrapped in a <span>
element with an ID, so that it can be ajax-updated.encodeChildren
in class UIComponentBase
IOException