- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener
The <o:deferredScript> is a component based on the standard <h:outputScript>
which defers the loading of the given script resource to the window load event. In other words, the given script
resource is only loaded when the window is really finished with loading. So, the enduser can start working with the
webpage without waiting for the additional scripts to be loaded. Usually, it are those kind of scripts which are just
for progressive enhancement and thus not essential for the functioning of the webpage.
This will give bonus points with among others the Google PageSpeed tool, on the contrary to placing the script at
bottom of body, or using defer="true" or even async="true".
Since 2.4 this will render the crossorigin attribute with a value of anonymous.
Since 3.13 this will also render the integrity attribute with a base64 encoded sha384 hash as SRI, see
also MDN.
Usage
Just use it the same way as a <h:outputScript>, with a library and name.
<o:deferredScript library="yourlibrary" name="scripts/filename.js" />
You can use the optional onbegin, onsuccess and onerror attributes
to declare JavaScript code which needs to be executed respectively right before the script is loaded,
right after the script is successfully loaded, and/or when the script loading failed.
- Since:
- 1.8
- Author:
- Bauke Scholtz
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.script.DeferredScript".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
ConstructorsConstructorDescriptionConstruct a newDeferredScriptcomponent whereby the renderer type is set toDeferredScriptRenderer.RENDERER_TYPE. -
Method Summary
Modifier and TypeMethodDescriptiongetGroup()Returns the group name on which the deferred script resources should be combined by CombinedResourceHandler.Returns the "library name" part of the resource identifier.getName()Returns the "resource name" part of the resource identifier.Returns the JavaScript code to execute right before the script loading begins.Returns the JavaScript code to execute when the script loading has failed.Returns the JavaScript code to execute when the script loading is successfully completed.voidprocessEvent(ComponentSystemEvent event) Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent).voidSets the group name on which the deferred script resources should be combined by CombinedResourceHandler.voidsetLibrary(String library) Sets the "library name" part of the resource identifier.voidSets the "resource name" part of the resource identifier.voidsetOnbegin(String onbegin) Sets the JavaScript code to execute right before the script loading begins.voidsetOnerror(String onerror) Sets the JavaScript code to execute when the script loading has failed.voidsetOnsuccess(String onsuccess) Sets the JavaScript code to execute when the script loading is successfully completed.Methods inherited from class org.omnifaces.component.script.ScriptFamily
encodeBegin, encodeEnd, 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.DeferredScript".- See Also:
-
-
Constructor Details
-
DeferredScript
public DeferredScript()Construct a newDeferredScriptcomponent whereby the renderer type is set toDeferredScriptRenderer.RENDERER_TYPE.
-
-
Method Details
-
processEvent
Move this component to body usingScriptFamily.moveToBody(ComponentSystemEvent). If successfully moved, then set the script resource as rendered, so that Faces won't auto-include it.- Specified by:
processEventin interfaceComponentSystemEventListener- Overrides:
processEventin classUIComponent
-
getLibrary
Returns the "library name" part of the resource identifier.- Returns:
- The library name.
-
setLibrary
Sets the "library name" part of the resource identifier.- Parameters:
library- The library name.
-
getName
Returns the "resource name" part of the resource identifier.- Returns:
- The resource name.
-
setName
Sets the "resource name" part of the resource identifier.- Parameters:
name- The resource name.
-
getGroup
Returns the group name on which the deferred script resources should be combined by CombinedResourceHandler. All deferred scripts resources having the same combined group name will be combined into a single deferred script in the place where the first member of the group occurs in the component tree.- Returns:
- The group name.
-
setGroup
Sets the group name on which the deferred script resources should be combined by CombinedResourceHandler. All deferred scripts resources having the same combined group name will be combined into a single deferred script in the place where the first member of the group occurs in the component tree.- Parameters:
group- The group name.
-
getOnbegin
Returns the JavaScript code to execute right before the script loading begins.- Returns:
- The onbegin script.
-
setOnbegin
Sets the JavaScript code to execute right before the script loading begins.- Parameters:
onbegin- The onbegin script.
-
getOnsuccess
Returns the JavaScript code to execute when the script loading is successfully completed.- Returns:
- The onsuccess script.
-
setOnsuccess
Sets the JavaScript code to execute when the script loading is successfully completed.- Parameters:
onsuccess- The onsuccess script.
-
getOnerror
Returns the JavaScript code to execute when the script loading has failed.- Returns:
- The onerror script.
-
setOnerror
Sets the JavaScript code to execute when the script loading has failed.- Parameters:
onerror- The onerror script.
-