For Older Versions of Tapestry
Approach 1: @Import
@Import may also be applied to individual methods, in which case the import operation only occurs when the method is invoked.
Note: When specifying a file to import, you'll often use the context: binding prefix to indicate that the file is stored in the web application context, and not on the classpath. Relative paths will be on the classpath, relative to the Java class. See Component Parameters for other binding prefix options.
Tapestry will ensure that the necessary <link> elements are added to the top of the document (in the <head> element). With Tapestry 5.3 and later the new elements are inserted at the bottom of the <head> element; in versions before 5.3 they appear at the top of the <head> element).
As with the annotation approach, adding the same asset multiple times does not create duplicate links.
... or, in a service implementation constructor:
Inside a component, you should use @Environmental, to highlight the fact that RenderSupport (like most environmental objects) is only available during rendering, not during action requests.
This is a very useful feature, as it reduces the number of requests needed to present a page to the user. It can be disabled, however, by setting the SymbolConstants.COMBINE_SCRIPTS configuration symbol to false in your application's module class (normally AppModule.java). By default it is enabled when in production mode and disabled otherwise.
Minification is accomplished using the ResourceMinimizer service. A YUI Compressor-based implementation is available, but this can be overridden.
IMPORTANT NOTE: The tapestry-core module only provides the empty infrastructure for supporting minification; the actual logic is supplied in the tapestry-yuicompressor module. To use it, you'll need to update your dependencies to include this module.
Gradle would be similar, of course. If you aren't using something like Maven or Gradle, you'll have to download the jar and its dependency (com.yahoo.platform.yui: yuicompressor) yourself.
Minification can be disabled by setting the tapestry.enable-minification to false in your application's module class (usually AppModule.java). By default it is enabled when in production mode and disabled otherwise.
Please test your applications well: the YUI Compressor code can be somewhat finicky about the application server and JDK version.
Each of these functions take a message and an optional pattern; if the pattern is provided, the message is interpolated on the pattern. The final message is displayed in the Blackbird console, which will make itself visible automatically.
In production mode, debug messages will be filtered out (they will not be visible until the user presses F2 to display the console, and then clicks the grayed out icon for debug messages). In development mode, debug messages are not filtered out.
With Tapestry 5.3 and later the Blackbird console has been removed; just use the standard console logging features (e.g.
console.log()) built into modern browsers.
Handling Slow Page Loads
If your page loads slowly (typically, because of scripts loaded from external sites), you may see a race condition where the user can click on a link before an event handler for that link has been wired up.
The client-side function
Tapestry.waitForPage() can be used in an element's onclick handler to force a wait for the page to fully load. In this race condition, the screen will dim and a message will appear advising the user to wait a moment; once the page is fully loaded, this modal dialog will be removed.
The correct usage is:
The constant MarkupConstants.WAIT_FOR_PAGE contains the part of this snippet inside the quotes.
The Standard Tapestry Library
Tapestry's client-side support, the standard Tapestry library, consists of
Tapestry defines a number of object and classes inside the Tapestry namespace.
It also adds a handful of methods to the Form class, and to Form elements. These are mostly related to input validation and determining element visibility.
The Tapestry Object $T()
The standard library adds a new function,
$T(). This function is used much like Prototype's
You may pass in an object id (as a string) or an object reference. The Tapestry Object is created on first invocation. Note: you'll see it as a property name _tapestry on the DOM object (which may be useful when debugging).
When Tapestry adds information to a DOM object, it does so in the Tapestry object. This helps avoid name conflicts, and groups all Tapestry-added properties into one place which is much easier to debug.
For example, you might store a value for an element in one place:
Then use it somewhere else:
Ajax Components and Mixins
Tapestry 5.4 and earlier come with the Prototype and Scriptaculous libraries ... no extra download is required. Tapestry will automatically link into your pages the prototype.js, scriptaculous.js, and effects.js libraries, as well as the Tapestry library, tapestry.js (which largely consists of support for form input validation). Starting with Tapestry 5.3, Underscore is also included.
Prototype and Scriptaculous Versions
Tapestry included only Prototype and Scriptaculous in versions prior to Tapestry 5.4. See Supported Environments and Versions for a matrix of prototype and scriptaculous versions supported by Tapestry.
In versions before 5.4, Tapestry used a modified version of the main Scriptaculous library, scriptaculous.js, with the library's default autoloading behavior turned off. This lets Tapestry and Tapestry components control which Scriptaculus scripts are loaded, rather than having all of them loaded unnecessarily.
If you need access to other Scriptaculous libraries, you can provide them as follows:
The Asset is injected, using the tapestry.scriptaculous configuration symbol to reference the location of the Scriptaculous library.
Even though the dragdrop.js library is stored inside a JAR file, Tapestry ensures that it can be accessed from the client web browser. A Tapestry URL within the virtual folder "/assets" is created; the file will be given a version number (the application version number if not specified more specifically) and will be sent to the browser with a far-future expires header (to encourage the browser to cache the file aggressively).
- getStylesheets : This method will return a list of stylesheet files (StylesheetLink-type object) associated to this stack
- getStacks : It is also possible to make a stack dependant of other stacks. All the stacks defined in this method will be loaded before the current stack.
When your new Stack is created, you have to define it in your AppModule.