...
Assets are most commonly stored in the web application's context folder ... stored inside the web application WAR file in the usual JEE fashion. In addition, Tapestry treats files stored on the classpath, with your Java class files, as assets visible to the web browser.
Assets are exposed to your code as instances of the Asset interface.
Assets in Templates
Assets can also be referenced directly in templates. Two binding prefixes exist for this: "asset:" and "context:". The "asset:" prefix can obtain assets from the classpath (the default) or from the web context (by specifying the "context:" domain explicitly):
Code Block | ||||
---|---|---|---|---|
| ||||
<img src="${asset:context:image/tapestry_banner.gif}" alt="Banner"/>
|
Info |
---|
This is an example of using a template expansion inside an ordinary element (rather than a component). |
Because accessing context assets is so common, the "context:" binding prefix was introduced:
Code Block | ||||
---|---|---|---|---|
| ||||
<img src="${context:image/tapestry_banner. |
...
gif}" alt="Banner"/>
|
Assets in Component Classes
...
Components learn about assets via injection. The @Inject annotation allows Assets to be injected into components as read-only properties. The path to the resource is specified using the Path annotation:
...
Unlike elsewhere in Tapestry, case matters. This is because Tapestry is dependent on the Servlet API and the Java runtime to access the underlying files, and those APIs, unlike Tapestry, are case sensitive. Be aware that some operating systems (such as Windows) are case insensitive, which may mask errors that will be revealed at deployment (if the deployment operating system is case sensitive, such as Linux).
Assets in Templates
Assets can also be referenced directly in templates. Two binding prefixes exist for this: "asset:" and "context:". The "asset:" prefix can obtain assets from the classpath (the default) or from the web context (by specifying the "context:" domain explicitly):
...
<img src="${asset:context:image/tapestry_banner.gif}" alt="Banner"/>
Info |
---|
This is an example of using a template expansion inside an ordinary element (rather than a component). |
Because accessing context assets is so common, the "context:" binding prefix was introduced:
...
<img src="${context:image/tapestry_banner.gif}" alt="Banner"/>
Relative Assets
You can use relative paths with domains (if you omit the prefix):
...
An override of the skin.root symbol would affect all references to the named asset.
Localization of Assets
Main Article: Localization
Assets are localized; Tapestry will search for a variation of the file appropriate to the effective locale for the request. In the previous example, a German user of the application may see a file named edit_de.png
(if such a file exists).
...
If you wish to create new domains for assets, for example to allow assets to be stored on the file system or in a database, you may define a new AssetFactory and contribute it to the AssetSource service configuration.
Asset URLs
...
By default, Tapestry secures file extensions ".class', ".tml" and ".properties". The list can be extended by contributing to the ResourceDigestGenerator service contribution:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public static void contributeResourceDigestGenerator(Configuration<String> configuration)
{
configuration.add("xyz");
}
|
Minimizing Assets
Since version 5.3, Tapestry provides a service, ResourceMinimizer, which will help to minimize all your static resources (principally CSS and JavaScript files).
...
Code Block | ||
---|---|---|
| ||
@Contribute(ResourceMinimizer.class)
@Primary
public static void contributeMinimizers(MappedConfiguration<String, ResourceMinimizer> configuration)
{
configuration.addInstance("text/coffeescript", CoffeeScriptMinimizer.class);
}
|
...