Package de.ipb_halle.molecularfaces.util
Class ResourceLoader
java.lang.Object
de.ipb_halle.molecularfaces.util.ResourceLoader
- All Implemented Interfaces:
jakarta.faces.event.ComponentSystemEventListener,jakarta.faces.event.FacesListener,Serializable,EventListener
public class ResourceLoader
extends Object
implements jakarta.faces.event.ComponentSystemEventListener, Serializable
This class enqueues resources and loads them either automatically or upon
request.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final jakarta.faces.component.UIComponentstatic final StringRenderer type for JavaScript resources.static final StringName of the facet that is used when adding JavaScript resources as facet components.static final StringResource library name.private static final longstatic final StringRenderer type for stylesheet resources.static final StringName of the facet that is used when adding stylesheet resources as facet components. -
Constructor Summary
ConstructorsConstructorDescriptionResourceLoader(jakarta.faces.component.UIComponent component) Wraps the given component and registers a PostAddToView event to it, in which this instance will attach its enqueued resources to the component tree. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddComponentToBodyAtTop(jakarta.faces.component.UIComponent componentToAdd, jakarta.faces.context.FacesContext context) private voidaddComponentToHead(jakarta.faces.component.UIComponent componentToAdd, jakarta.faces.context.FacesContext context) private voidaddComponentToResourceContainerInFacet(jakarta.faces.component.UIComponent component, String facetName, Map<String, jakarta.faces.component.UIComponent> facets) voidEnqueues loading of a stylesheet file that will be loaded via the JavaScript classmolecularfaces.ResourcesLoader.voidAdds a stylesheet file as facet resource component to the wrapped component.voidaddCssResource(String resource) Enqueues loading of a stylesheet resource file that will be added via JSF's resource mechanism.voidaddCssResourceAsFacetComponent(String resource) Adds a stylesheet resource component as facet to the wrapped component.voidAdds a JavaScript file as facet resource component to the wrapped component.voidEnqueues loading of a JavaScript file that will be loaded in the top of <body> via the JavaScript classmolecularfaces.ResourcesLoader.voidaddScriptExtToHead(String src) Enqueues loading of a JavaScript file that will be loaded in the <head> via the JavaScript classmolecularfaces.ResourcesLoader.voidaddScriptResourceAsFacetComponent(String resource) Adds a JavaScript resource component as facet to the wrapped component.voidaddScriptResourceToBodyAtTop(String resource) Enqueues loading of a JavaScript resource file that will be added via JSF's resource mechanism to the top of <body>.voidaddScriptResourceToHead(String resource) Enqueues loading of a JavaScript resource file that will be added via JSF's resource mechanism to the <head>.private jakarta.faces.component.UIComponentcreateResourceComponent(String resourceName, String rendererType) encodeLoadExtResources(String loaderJSVar) Generates a JavaScript code fragment for loading resources that have been enqueued for loading viamolecularfaces.ResourcesLoader.private jakarta.faces.component.UIComponentfindBodyComponent(jakarta.faces.context.FacesContext context) private voidloadCssResources(jakarta.faces.context.FacesContext context) private voidloadScriptResources(jakarta.faces.context.FacesContext context) voidprocessEvent(jakarta.faces.event.ComponentSystemEvent event)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
RESOURCES_LIBRARY_NAME
Resource library name.- See Also:
-
JAVASCRIPT_FACET_NAME
Name of the facet that is used when adding JavaScript resources as facet components.- See Also:
-
STYLESHEET_FACET_NAME
Name of the facet that is used when adding stylesheet resources as facet components.- See Also:
-
JAVASCRIPT
Renderer type for JavaScript resources.- See Also:
-
STYLESHEET
Renderer type for stylesheet resources.- See Also:
-
component
private final jakarta.faces.component.UIComponent component -
scriptResourcesToLoadInHead
-
scriptResourcesToLoadInBodyAtTop
-
scriptsExtToLoadInHead
-
scriptsExtToLoadInBodyAtTop
-
cssResourcesToLoad
-
cssExtToLoad
-
-
Constructor Details
-
ResourceLoader
public ResourceLoader(jakarta.faces.component.UIComponent component) Wraps the given component and registers a PostAddToView event to it, in which this instance will attach its enqueued resources to the component tree.- Parameters:
component- UI component
-
-
Method Details
-
processEvent
public void processEvent(jakarta.faces.event.ComponentSystemEvent event) throws jakarta.faces.event.AbortProcessingException - Specified by:
processEventin interfacejakarta.faces.event.ComponentSystemEventListener- Throws:
jakarta.faces.event.AbortProcessingException
-
addScriptResourceToHead
Enqueues loading of a JavaScript resource file that will be added via JSF's resource mechanism to the <head>.- Parameters:
resource- name of the file in the web project's resource library
-
getScriptResourcesToLoadInHead
- Returns:
- An immutable
Setof the JavaScript resources enqueued byaddScriptResourceToHead(String)and that have not been loaded via {processEvent(ComponentSystemEvent)yet.
-
addScriptResourceToBodyAtTop
Enqueues loading of a JavaScript resource file that will be added via JSF's resource mechanism to the top of <body>.Note: There is no guarantee on the load order among the resources enqueued by this method.
- Parameters:
resource- name of the file in the web project's resource library
-
getScriptResourcesToLoadInBodyAtTop
- Returns:
- An immutable
Setof the JavaScript resources enqueued byaddScriptResourceToBodyAtTop(String)and that have not been loaded via {processEvent(ComponentSystemEvent)yet.
-
addScriptExtToHead
Enqueues loading of a JavaScript file that will be loaded in the <head> via the JavaScript classmolecularfaces.ResourcesLoader. The code snippet can be requested viaencodeLoadExtResources(String).- Parameters:
src- path of the file
-
getScriptsExtToLoadInHead
- Returns:
- An immutable
Setof the JavaScript resources enqueued byaddScriptExtToHead(String).
-
addScriptExtToBodyAtTop
Enqueues loading of a JavaScript file that will be loaded in the top of <body> via the JavaScript classmolecularfaces.ResourcesLoader. The code snippet can be requested viaencodeLoadExtResources(String).- Parameters:
src- path of the file
-
getScriptsExtToLoadInBodyAtTop
- Returns:
- An immutable
Setof the JavaScript resources enqueued byaddScriptExtToBodyAtTop(String).
-
addCssResource
Enqueues loading of a stylesheet resource file that will be added via JSF's resource mechanism.- Parameters:
resource- name of the file in the web project's resource library
-
getCssResourcesToLoad
- Returns:
- An immutable
Setof the stylesheet resources enqueued byaddCssResource(String)and that have not been loaded via {processEvent(ComponentSystemEvent)yet.
-
addCssExt
Enqueues loading of a stylesheet file that will be loaded via the JavaScript classmolecularfaces.ResourcesLoader. The code snippet can be requested viaencodeLoadExtResources(String).- Parameters:
href- path of the file
-
getCssExtToLoad
- Returns:
- An immutable
Setof the stylesheet resources enqueued byaddCssExt(String).
-
addScriptResourceAsFacetComponent
Adds a JavaScript resource component as facet to the wrapped component. The wrapped component is responsible for rendering its facets.- Parameters:
resource- name of the file in the web project's resource library
-
addScriptExtAsFacetComponent
Adds a JavaScript file as facet resource component to the wrapped component. The wrapped component is responsible for rendering its facets.- Parameters:
src- path of the file
-
addCssResourceAsFacetComponent
Adds a stylesheet resource component as facet to the wrapped component. The wrapped component is responsible for rendering its facets.- Parameters:
resource- name of the file in the web project's resource library
-
addCssExtAsFacetComponent
Adds a stylesheet file as facet resource component to the wrapped component. The wrapped component is responsible for rendering its facets.- Parameters:
href- path of the file
-
loadScriptResources
private void loadScriptResources(jakarta.faces.context.FacesContext context) -
loadCssResources
private void loadCssResources(jakarta.faces.context.FacesContext context) -
createResourceComponent
-
addComponentToHead
private void addComponentToHead(jakarta.faces.component.UIComponent componentToAdd, jakarta.faces.context.FacesContext context) -
addComponentToBodyAtTop
private void addComponentToBodyAtTop(jakarta.faces.component.UIComponent componentToAdd, jakarta.faces.context.FacesContext context) -
findBodyComponent
private jakarta.faces.component.UIComponent findBodyComponent(jakarta.faces.context.FacesContext context) -
addComponentToResourceContainerInFacet
-
encodeLoadExtResources
Generates a JavaScript code fragment for loading resources that have been enqueued for loading viamolecularfaces.ResourcesLoader.- Parameters:
loaderJSVar- JavaScript variable name of themolecularfaces.ResourcesLoaderinstance- Returns:
- JavaScript code
-