Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tapestry5.services.javascript
Interface JavaScriptSupport

All Known Implementing Classes:
  JavaScriptSupportImpl

    public interface JavaScriptSupport

An environmental that acts as a replacement for the `RenderSupport` environmental, renaming and streamlining the key methods. JavaScriptSupport 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 Document once.

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 Summary
`void` | `addInitializerCall(InitializationPriority priority, java.lang.String functionName, JSONArray parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addInitializerCall(InitializationPriority priority, java.lang.String functionName, JSONObject parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addInitializerCall(InitializationPriority priority, java.lang.String functionName, java.lang.String parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addInitializerCall(java.lang.String functionName, JSONArray parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addInitializerCall(java.lang.String functionName, JSONObject parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addInitializerCall(java.lang.String functionName, java.lang.String parameter)` Adds a call to a client-side function inside the Tapestry.Initializer namespace.
`void` | `addScript(InitializationPriority priority, java.lang.String format, java.lang.Object... arguments)` Adds initialization script at the specified priority.
`void` | `addScript(java.lang.String format, java.lang.Object... arguments)` Adds initialization script at `InitializationPriority.NORMAL` priority.
`java.lang.String` | `allocateClientId(ComponentResources resources)` As with `allocateClientId(String)` but uses the id of the component extracted from the resources.
`java.lang.String` | `allocateClientId(java.lang.String id)` Allocates a unique id based on the component's id.
`void` | `autofocus(FieldFocusPriority priority, java.lang.String fieldId)` Invoked to set focus on a rendered field.
`void` | `importJavaScriptLibrary(Asset asset)` Imports a JavaScript library as part of the rendered page.
`void` | `importJavaScriptLibrary(java.lang.String libraryURL)` Import a Javascript library with an arbitrary URL.
`void` | `importStack(java.lang.String stackName)` Imports a `JavaScriptStack` by name, a related set of JavaScript libraries and stylesheets.
`void` | `importStylesheet(Asset stylesheet)` A convenience method that wraps the Asset as a `StylesheetLink`.
`void` | `importStylesheet(StylesheetLink stylesheetLink)` Imports a Cascading Style Sheet file as part of the rendered page.

Method Detail

### allocateClientId

    java.lang.String allocateClientId(java.lang.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`

### allocateClientId

    java.lang.String allocateClientId(ComponentResources resources)

  As with `allocateClientId(String)` but uses the id of the component extracted from the resources.

  Parameters:
    `resources` - of the component which requires an id
  Returns:
    a unique id for this rendering of the page

### addScript

    void addScript(java.lang.String format,
                   java.lang.Object... arguments)

  Adds initialization script at `InitializationPriority.NORMAL` priority.

  Parameters:
    `format` - format string (as per `String.format(String, Object...)`
    `arguments` - arguments referenced by format specifiers

### addScript

    void addScript(InitializationPriority priority,
                   java.lang.String format,
                   java.lang.Object... arguments)

  Adds initialization script at the specified priority.

  Parameters:
    `priority` - priority to use when adding the script
    `format` - format string (as per `String.format(String, Object...)`
    `arguments` - arguments referenced by format specifiers

### addInitializerCall

    void addInitializerCall(java.lang.String functionName,
                            JSONObject parameter)

  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(java.lang.String functionName,
                            JSONArray parameter)

  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,
                            java.lang.String functionName,
                            JSONArray parameter)

  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,
                            java.lang.String functionName,
                            JSONObject parameter)

  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(java.lang.String functionName,
                            java.lang.String parameter)

  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,
                            java.lang.String functionName,
                            java.lang.String parameter)

  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

    void 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.

  See Also:
    `Import`

### importStylesheet

    void importStylesheet(Asset stylesheet)

  A convenience method that wraps the Asset as a `StylesheetLink`.

  Parameters:
    `stylesheet` - asset for the stylesheet
  See Also:
    `importStylesheet(StylesheetLink)`

### importStylesheet

    void 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.

  Parameters:
    `stylesheetLink` - encapsulates the link URL plus any additional options

### importStack

    void importStack(java.lang.String stackName)

  Imports a `JavaScriptStack` by name, a related set of JavaScript libraries and stylesheets. Stacks are contributions to the `JavaScriptStackSource` service. When JavaScript aggregation in enabled, the stack will be represented by a single virtual URL; otherwise the individual asset URLs of the stack will be added to the document.

  Parameters:
    `stackName` - the name of the stack (case is ignored); the stack must exist

### importJavaScriptLibrary

    void importJavaScriptLibrary(java.lang.String libraryURL)

  Import a Javascript library with an arbitrary URL.

### autofocus

    void autofocus(FieldFocusPriority priority,
                   java.lang.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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2012 The Apache Software Foundation.