Interface JavaScriptSupport

  • All Known Implementing Classes:
    JavaScriptSupportImpl

    public interface JavaScriptSupport
    The JavaScriptSupport environmental is very stateful, accumulating JavaScript stacks, libraries and initialization code until the end of the main page render; it then updates the rendered DOM (adding <script> tags to the <head> and <body>) before the document is streamed to the client. JavaScriptSupport is normally accessed within a component by using the Environmental annotation on a component field. In addition, JavaScriptSupport may also be accessed as a service (the service internally delegates to the current environmental instance), which is useful for service-layer objects. The term "import" is used on many methods to indicate that the indicated resource (stack, library or stylesheet) will only be added to the final cocument once, even when there are repeated calls. The name is slightly a misnomer, since there's a side-line of importStylesheet(StylesheetLink) as well. JavaScriptSupport works equally well inside an Ajax request that produces a JSON-formatted partial page update response.
    Since:
    5.2.0
    See Also:
    DocumentLinker
    • Method Detail

      • allocateClientId

        String allocateClientId​(String id)
        Allocates a unique id based on the component's id. In some cases, the return value will not precisely match the input value (an underscore and a unique index value may be appended).
        Parameters:
        id - the component id from which a unique id will be generated
        Returns:
        a unique id for this rendering of the page
        See Also:
        IdAllocator
      • addInitializerCall

        void addInitializerCall​(String functionName,
                                JSONObject parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at InitializationPriority.NORMAL priority.
        Parameters:
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - object to pass to the client-side function
      • addInitializerCall

        void addInitializerCall​(String functionName,
                                JSONArray parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at InitializationPriority.NORMAL priority.
        Parameters:
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - array of parameters to pass to the client-side function
        Since:
        5.3
      • addInitializerCall

        void addInitializerCall​(InitializationPriority priority,
                                String functionName,
                                JSONArray parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at InitializationPriority.NORMAL priority.
        Parameters:
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - array of parameters to pass to the client-side function
        Since:
        5.3
      • addInitializerCall

        void addInitializerCall​(InitializationPriority priority,
                                String functionName,
                                JSONObject parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at the specified priority.
        Parameters:
        priority - priority to use when adding the script
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - object to pass to the client-side function
      • addInitializerCall

        void addInitializerCall​(String functionName,
                                String parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at InitializationPriority.NORMAL priority.
        Parameters:
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - string to pass to function (typically, a client id)
      • addInitializerCall

        void addInitializerCall​(InitializationPriority priority,
                                String functionName,
                                String parameter)
        Deprecated.
        Deprecated in 5.4; refactor to use JavaScript modules instead
        Adds a call to a client-side function inside the Tapestry.Initializer namespace. Calls to this method are aggregated into a call to the Tapestry.init() function. Initialization occurs at the specified priority.
        Parameters:
        priority - priority to use when adding the script
        functionName - name of client-side function (within Tapestry.Initializer namespace) to execute
        parameter - string to pass to function (typically, a client id)
      • importJavaScriptLibrary

        JavaScriptSupport importJavaScriptLibrary​(Asset asset)
        Imports a JavaScript library as part of the rendered page. Libraries are added in the order they are first imported; duplicate imports are ignored. Libraries are added to the page serially (whereas modules may be loaded in parallel), and all libraries are added before any modules are loaded. Because of this, it is preferrable to organize your JavaScript into modules, rather than libraries.
        Returns:
        this JavaScriptSupport, for further configuration
        See Also:
        Import
      • importStylesheet

        JavaScriptSupport importStylesheet​(StylesheetLink stylesheetLink)
        Imports a Cascading Style Sheet file as part of the rendered page. Stylesheets are added in the order they are first imported; duplicate imports are ignored. Starting in 5.4, importing a stylesheet imports the core stack as well (with its stylesheets); this ensures that the imported stylesheet(s) can override rules from Tapestry's default stylesheets.
        Parameters:
        stylesheetLink - encapsulates the link URL plus any additional options
        Returns:
        this JavaScriptSupport, for further configuration
      • autofocus

        JavaScriptSupport autofocus​(FieldFocusPriority priority,
                                    String fieldId)
        Invoked to set focus on a rendered field. Takes into account priority, meaning that a field with errors will take precedence over a merely required field, and over a field that is optional. The value FieldFocusPriority.OVERRIDE can be used to force a particular field to receive focus.
        Parameters:
        priority - focus is set only if the provided priority is greater than the current priority
        fieldId - id of client-side element to take focus
      • require

        Initialization require​(String moduleName)
        Requires a JavaScript module by name. On the client, this will require() the module and (optionally) de-reference a function exported by the module (or, treat the module as exporting a single implicit function). The function will be invoked. Use the returned Initialization to specify the function name to invoke, and the parameters to pass to the function. In some cases, a module exports no functions, but performs some initialization (typically, adding document-level event handlers), in which case a call to require() is sufficient. In cases where the module, or a function within the module, are invoked with no parameters, the calls will be collapsed into a single invocation. If the module is part of a JavaScript stack, then the stack will be imported; this is important when JavaScript aggregation is enabled, but also ensures that libraries in the stack are loaded before the module (for cases where the module has dependencies on libraries not wrapped as AMD modules).
        Parameters:
        moduleName - the name of the module to require
        Returns:
        Initialization instance, used to configure function name, arguments, etc.
        Since:
        5.4