Class AddPageResources
- All Implemented Interfaces:
Future<Void>,Associator,Eligible
<style>...</style> or
<script ...></script> nodes to the web console’s
<head> node on behalf of components that provide such resources.Adding resource references causes the browser to issue GET request that
(usually) refer to resources that are then provided by the component
that created the AddPageResources event.
The sequence of events is shown in the diagram.
See ResourceRequest for details about the processing
of the PageResourceRequest.
The GET request may also, of course, refer to a resource from
another server and thus not result in a PageResourceRequest.
Adding a <script src=...></script> node to a document’s <head>
causes the referenced JavaScript to be loaded asynchronously. This
can cause problems if a dynamically added library relies on another
library to be available. Script resources are therefore specified using
the AddPageResources.ScriptResource class, which allows to specify loading
dependencies between resources. The code in the browser delays the
addition of a <script> node until all other script resources that
it depends on are loaded.
Some libraries provided as page resources may already be required by the
JavaScript web console code (especially by the resource manager that handles
the delayed loading). They can therefore not be loaded by this
mechanism, which depends on the web console code. Such page resources
may be “pre-loaded” by adding the appropriate script element to the
initial web console page. In order to make the pre-loading known to the
resource manager, the script elements must carry an attribute
data-jgwc-provides with a comma separated list of JavaScript resource
names provided by loading the script resource. The name(s) must match
the name(s) used in the AddPageResources request generated
by the PageResourceProvider for the pre-loaded resource(s).
Here’s an example (for a web console using the
FreeMarkerConsoleWeblet to generate the initial web console page):
<script data-jgwc-provides="jquery"
src="${renderSupport.pageResource('jquery/jquery' + minifiedExtension + '.js')}">
</script>;
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a script resource that is to be loaded or evaluated by the browser.Nested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Field Summary
Fields inherited from class org.jgrapes.webconsole.base.events.ConsoleCommand
mapperFields inherited from class org.jgrapes.core.internal.EventBase
completed, completionEvents, invokedFor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the URI of a CSS resource that is to be added to the header section of the web console page.addScriptResource(AddPageResources.ScriptResource scriptResource) Add the URI of a JavaScript resource that is to be added to the header section of the web console page.URI[]cssUris()Return all CSS URIs.voidEmits the JSON notification using the given writer.Return all script URIssetCssSource(String cssSource) Methods inherited from class org.jgrapes.webconsole.base.events.ConsoleCommand
emitJson, toJsonMethods inherited from class org.jgrapes.core.Event
addCompletionEvent, associated, cancel, channels, channels, completionEvents, currentResults, defaultCriterion, forChannels, get, get, handled, handlingError, isCancelled, isDone, isEligibleFor, isStopped, processedBy, results, results, resumeHandling, setAssociated, setChannels, setRequiresResult, setResult, stop, suspendHandling, suspendHandling, tieTo, toStringMethods inherited from class org.jgrapes.core.internal.EventBase
disableTracking, enqueued, firstResultAssigned, isTracked, onCompletionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jgrapes.core.Associator
associated, associated, associated, associatedGetMethods inherited from interface java.util.concurrent.Future
exceptionNow, resultNow, state
-
Constructor Details
-
AddPageResources
public AddPageResources()
-
-
Method Details
-
addScriptResource
Add the URI of a JavaScript resource that is to be added to the header section of the web console page.- Parameters:
scriptResource- the resource to add- Returns:
- the event for easy chaining
-
scriptResources
Return all script URIs- Returns:
- the result
-
addCss
Add the URI of a CSS resource that is to be added to the header section of the web console page.- Parameters:
uri- the URI- Returns:
- the event for easy chaining
-
cssUris
Return all CSS URIs.- Returns:
- the result
-
cssSource
- Returns:
- the cssSource
-
setCssSource
- Parameters:
cssSource- the cssSource to set
-
emitJson
Description copied from class:ConsoleCommandEmits the JSON notification using the given writer.Derived classes usually simply call
ConsoleCommand.emitJson(Writer, String, Object...)with the method name and parameters.- Specified by:
emitJsonin classConsoleCommand- Parameters:
writer- the writer- Throws:
IOException
-