Class JavaScriptSupportImpl
-
- org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl
-
- All Implemented Interfaces:
JavaScriptSupport
public class JavaScriptSupportImpl extends implements JavaScriptSupport
-
-
Constructor Summary
Constructors Constructor Description JavaScriptSupportImpl(DocumentLinker linker, JavaScriptStackSource javascriptStackSource, JavaScriptStackPathConstructor stackPathConstructor, BooleanHook suppressCoreStylesheetsHook)
JavaScriptSupportImpl(DocumentLinker linker, JavaScriptStackSource javascriptStackSource, JavaScriptStackPathConstructor stackPathConstructor, IdAllocator idAllocator, boolean partialMode, BooleanHook suppressCoreStylesheetsHook)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
functionName, parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
functionName, JSONArray parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
functionName, JSONObject parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
addInitializerCall(InitializationPriority priority, functionName, parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
addInitializerCall(InitializationPriority priority, functionName, JSONArray parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
addInitializerCall(InitializationPriority priority, functionName, JSONObject parameter)
Adds a call to a client-side function inside the Tapestry.Initializer namespace.void
addModuleConfigurationCallback(ModuleConfigurationCallback callback)
Adds a module configuration callback for this request.void
format, ... arguments)
Adds initialization script atInitializationPriority.NORMAL
priority.void
addScript(InitializationPriority priority, format, ... arguments)
Adds initialization script at the specified priority.id)
Allocates a unique id based on the component's id.allocateClientId(ComponentResources resources)
As withJavaScriptSupport.allocateClientId(String)
but uses the id of the component extracted from the resources.JavaScriptSupport
autofocus(FieldFocusPriority priority, fieldId)
Invoked to set focus on a rendered field.void
commit()
JavaScriptSupport
libraryURL)
Import a Javascript library with an arbitrary URL.JavaScriptSupport
importJavaScriptLibrary(Asset asset)
Imports a JavaScript library as part of the rendered page.JavaScriptSupport
stackName)
Imports aJavaScriptStack
by name, a related set of JavaScript libraries and stylesheets.JavaScriptSupport
importStylesheet(Asset stylesheet)
A convenience method that wraps the Asset as aStylesheetLink
.JavaScriptSupport
importStylesheet(StylesheetLink stylesheetLink)
Imports a Cascading Style Sheet file as part of the rendered page.Initialization
moduleName)
Requires a JavaScript module by name.
-
-
-
Constructor Detail
-
JavaScriptSupportImpl
public JavaScriptSupportImpl(DocumentLinker linker, JavaScriptStackSource javascriptStackSource, JavaScriptStackPathConstructor stackPathConstructor, BooleanHook suppressCoreStylesheetsHook)
-
JavaScriptSupportImpl
public JavaScriptSupportImpl(DocumentLinker linker, JavaScriptStackSource javascriptStackSource, JavaScriptStackPathConstructor stackPathConstructor, IdAllocator idAllocator, boolean partialMode, BooleanHook suppressCoreStylesheetsHook)
- Parameters:
linker
- responsible for assembling all the information gathered by JavaScriptSupport and attaching it to the Document (for a full page render) or to the JSON response (in a partial render)javascriptStackSource
- source of information aboutJavaScriptStack
s, used when handling the import of libraries and stacks (often, to handle transitive dependencies)stackPathConstructor
- encapsulates the knowledge of how to represent a stack (which may be converted from a series of JavaScript libraries into a single virtual JavaScript library)idAllocator
- used when allocating unique ids (it is usually pre-initialized in an Ajax request to ensure that newly allocated ids do not conflict with previous renders and partial updates)partialMode
- if true, then the JSS configures itself for a partial page render (part of an Ajax request) which automatically assumes the "core" library has been added (to the original page render)suppressCoreStylesheetsHook
- a hook that enables ignoring CSS files on the core stack
-
-
Method Detail
-
commit
public void commit()
-
addInitializerCall
public void addInitializerCall(InitializationPriority priority, functionName, JSONObject parameter)
Description copied from interface:JavaScriptSupport
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.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
- Parameters:
priority
- priority to use when adding the scriptfunctionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- object to pass to the client-side function
-
addInitializerCall
public void functionName, JSONArray parameter)
Description copied from interface:JavaScriptSupport
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 atInitializationPriority.NORMAL
priority.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
- Parameters:
functionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- array of parameters to pass to the client-side function
-
addInitializerCall
public void addInitializerCall(InitializationPriority priority, functionName, JSONArray parameter)
Description copied from interface:JavaScriptSupport
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 atInitializationPriority.NORMAL
priority.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
functionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- array of parameters to pass to the client-side function
-
addInitializerCall
public void functionName, JSONObject parameter)
Description copied from interface:JavaScriptSupport
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 atInitializationPriority.NORMAL
priority.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
- Parameters:
functionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- object to pass to the client-side function
-
addInitializerCall
public void addInitializerCall(InitializationPriority priority, functionName, parameter)
Description copied from interface:JavaScriptSupport
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.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
- Parameters:
priority
- priority to use when adding the scriptfunctionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- string to pass to function (typically, a client id)
-
addInitializerCall
public void functionName, parameter)
Description copied from interface:JavaScriptSupport
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 atInitializationPriority.NORMAL
priority.- Specified by:
addInitializerCall
in interfaceJavaScriptSupport
- Parameters:
functionName
- name of client-side function (within Tapestry.Initializer namespace) to executeparameter
- string to pass to function (typically, a client id)
-
addScript
public void addScript(InitializationPriority priority, format, ... arguments)
Description copied from interface:JavaScriptSupport
Adds initialization script at the specified priority.- Specified by:
addScript
in interfaceJavaScriptSupport
- Parameters:
priority
- priority to use when adding the scriptformat
- format string (as perarguments
- arguments referenced by format specifiers
-
addScript
public void format, ... arguments)
Description copied from interface:JavaScriptSupport
Adds initialization script atInitializationPriority.NORMAL
priority.- Specified by:
addScript
in interfaceJavaScriptSupport
- Parameters:
format
- format string (as perarguments
- arguments referenced by format specifiers
-
addModuleConfigurationCallback
public void addModuleConfigurationCallback(ModuleConfigurationCallback callback)
Description copied from interface:JavaScriptSupport
Adds a module configuration callback for this request.- Specified by:
addModuleConfigurationCallback
in interfaceJavaScriptSupport
- Parameters:
callback
- aModuleConfigurationCallback
. It cannot be null.- See Also:
DocumentLinker.addModuleConfigurationCallback(ModuleConfigurationCallback)
-
allocateClientId
public allocateClientId(ComponentResources resources)
Description copied from interface:JavaScriptSupport
As withJavaScriptSupport.allocateClientId(String)
but uses the id of the component extracted from the resources.- Specified by:
allocateClientId
in interfaceJavaScriptSupport
- Parameters:
resources
- of the component which requires an id- Returns:
- a unique id for this rendering of the page
-
allocateClientId
public id)
Description copied from interface:JavaScriptSupport
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).- Specified by:
allocateClientId
in interfaceJavaScriptSupport
- 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
-
importJavaScriptLibrary
public JavaScriptSupport importJavaScriptLibrary(Asset asset)
Description copied from interface:JavaScriptSupport
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.- Specified by:
importJavaScriptLibrary
in interfaceJavaScriptSupport
- Returns:
- this JavaScriptSupport, for further configuration
- See Also:
Import
-
importJavaScriptLibrary
public libraryURL)
Description copied from interface:JavaScriptSupport
Import a Javascript library with an arbitrary URL. Please refer to the notes about libraries vs. modules.- Specified by:
importJavaScriptLibrary
in interfaceJavaScriptSupport
-
importStylesheet
public JavaScriptSupport importStylesheet(Asset stylesheet)
Description copied from interface:JavaScriptSupport
A convenience method that wraps the Asset as aStylesheetLink
.- Specified by:
importStylesheet
in interfaceJavaScriptSupport
- Parameters:
stylesheet
- asset for the stylesheet- Returns:
- this JavaScriptSupport, for further configuration
- See Also:
JavaScriptSupport.importStylesheet(StylesheetLink)
-
importStylesheet
public JavaScriptSupport importStylesheet(StylesheetLink stylesheetLink)
Description copied from interface:JavaScriptSupport
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.- Specified by:
importStylesheet
in interfaceJavaScriptSupport
- Parameters:
stylesheetLink
- encapsulates the link URL plus any additional options- Returns:
- this JavaScriptSupport, for further configuration
-
importStack
public stackName)
Description copied from interface:JavaScriptSupport
Imports aJavaScriptStack
by name, a related set of JavaScript libraries and stylesheets. Stacks are contributions to theJavaScriptStackSource
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. Please refer to the notes about libraries vs. modules.- Specified by:
importStack
in interfaceJavaScriptSupport
- Parameters:
stackName
- the name of the stack (case is ignored); the stack must exist- Returns:
- this JavaScriptSupport, for further configuration
-
autofocus
public JavaScriptSupport autofocus(FieldFocusPriority priority, fieldId)
Description copied from interface:JavaScriptSupport
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 valueFieldFocusPriority.OVERRIDE
can be used to force a particular field to receive focus.- Specified by:
autofocus
in interfaceJavaScriptSupport
- Parameters:
priority
- focus is set only if the provided priority is greater than the current priorityfieldId
- id of client-side element to take focus
-
require
public moduleName)
Description copied from interface:JavaScriptSupport
Requires a JavaScript module by name. On the client, this willrequire()
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 returnedInitialization
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).- Specified by:
require
in interfaceJavaScriptSupport
- Parameters:
moduleName
- the name of the module to require- Returns:
- Initialization instance, used to configure function name, arguments, etc.
-
-