Class AddPageResources

java.lang.Object
org.jgrapes.core.internal.EventBase<Void>
org.jgrapes.core.Event<Void>
org.jgrapes.webconsole.base.events.ConsoleCommand
org.jgrapes.webconsole.base.events.AddPageResources
All Implemented Interfaces:
Future<Void>, org.jgrapes.core.Associator, org.jgrapes.core.Eligible

public class AddPageResources extends ConsoleCommand
Adds <link …/>, <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.

WebConsole Ready Event Sequence

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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents 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

    mapper

    Fields inherited from class org.jgrapes.core.internal.EventBase

    completed, completionEvents, invokedFor
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addCss(URI uri)
    Add the URI of a CSS resource that is to be added to the header section of the web console page.
    Add the URI of a JavaScript resource that is to be added to the header section of the web console page.
     
    URI[]
    Return all CSS URIs.
    void
    emitJson(Writer writer)
    Emits the JSON notification using the given writer.
    Return all script URIs
    setCssSource(String cssSource)
     

    Methods inherited from class org.jgrapes.webconsole.base.events.ConsoleCommand

    emitJson, toJson

    Methods 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, toString

    Methods inherited from class org.jgrapes.core.internal.EventBase

    disableTracking, enqueued, firstResultAssigned, isTracked, onCompletion

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.jgrapes.core.Associator

    associated, associated, associated, associatedGet

    Methods inherited from interface java.util.concurrent.Future

    exceptionNow, resultNow, state