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 the key methods. JavascriptSupport is very stateful, accumulating JavaScript 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.

Since:
5.2.0

Method Summary
 void addInitializerCall(InitializationPriority priority, String functionName, JSONObject parameter)
          Adds a call to a client-side function inside the Tapestry.Initializer namespace.
 void addInitializerCall(InitializationPriority priority, String functionName, String parameter)
          Adds a call to a client-side function inside the Tapestry.Initializer namespace.
 void addInitializerCall(String functionName, JSONObject parameter)
          Adds a call to a client-side function inside the Tapestry.Initializer namespace.
 void addInitializerCall(String functionName, String parameter)
          Adds a call to a client-side function inside the Tapestry.Initializer namespace.
 void addScript(InitializationPriority priority, String format, Object... arguments)
          Adds initialization script at the specified priority.
 void addScript(String format, Object... arguments)
          Adds initialization script at InitializationPriority.NORMAL priority.
 String allocateClientId(ComponentResources resources)
          As with allocateClientId(String) but uses the id of the component extracted from the resources.
 String allocateClientId(String id)
          Allocates a unique id based on the component's id.
 void importJavascriptLibrary(Asset asset)
          Imports a JavaScript library as part of the rendered page.
 

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

allocateClientId

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(String format,
               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,
               String format,
               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(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(InitializationPriority priority,
                        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(String functionName,
                        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,
                        String functionName,
                        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:
IncludeJavaScriptLibrary


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.