• Assets should be stored along with the page you are creating.
  • General resources (CSS, JS, and images should be put in (you could try other spots, but I had trouble finding them with Jetty)
    • src/main/webapp/css
    • src/main/webapp/js
    • src/main/webapp/images
  • In case of CSS/JS/images for components, have a look into the way the T5 Grid or Palette component is constructed, since they have their own js, css and images.

[Thanks go to Daniel Jue, who answered my question on June 7, 2007]

For example, if you have this file:

src/main/webapp/css/MyStyle.css

You can access it in your page or component Java class like this:

@Inject
@Path("context:css/MyStyle.css")
private Asset thestyle;

public Asset getTheStyle() { return thestyle; }

And then in your page or component template:

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>My Title</title>
<link rel="stylesheet" type="text/css" href="${thestyle}"/>
</head>
...
</html>

Similarly, having src/main/webapp/images/MyLogo.gif Page or Component Class:

@Inject
@Path("context:images/MyLogo.gif")
private Asset thelogo;

public Asset getTheLogo() { return theLogo; }

Page or Component Template (the html):

<img src="${thelogo}" />
  • No labels