public class OnloadScript extends ScriptFamily implements SystemEventListener
<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 |
encodeBegin(FacesContext context)
If this component is rendered and there are any children, then start the
<script> element. |
void |
encodeEnd(FacesContext context)
If this component is rendered and there are any children, then end the
<script> element. |
boolean |
isListenerForSource(Object source)
|
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. |
void |
processEvent(SystemEvent event)
If the event is a
PreRenderViewEvent and the current request is an ajax request and this component is
rendered and there are any children, then encode the children as Ajax.oncomplete(String...) . |
getFamily, getRendersChildren
addClientBehavior, 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, 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 boolean isListenerForSource(Object source)
isListenerForSource
in interface SystemEventListener
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. Else if the event is a
PostRestoreStateEvent
and the current request is an ajax request, then subscribe to the
PreRenderViewEvent
event.processEvent
in interface ComponentSystemEventListener
processEvent
in class UIComponent
AbortProcessingException
public void processEvent(SystemEvent event) throws AbortProcessingException
PreRenderViewEvent
and the current request is an ajax request and this component is
rendered and there are any children, 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