Sunday, October 31, 2004

How to use Tiles with JSF Applications

Found some instructions on using tiles with JSF without struts, so I should be ok

http://forum.exadel.com/viewtopic.php?t=968

URL: http://www.exadel.com/downloads/jsf/examples/jsf-tiles.war (2.14M)
This short example shows how use JSF together with Tiles. All you have to do is add struts.jar from the Struts1.1 distributive to your classpath. Including struts.jar does not mean that Struts itself is required to use with Tiles. Tiles packages are distributed inside the struts.jar. No other funclionality of the Struts Framework will be involved.

Useful Tips:

1. This is a snippet from web.xml that makes Tiles enabled:
Code:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>TilesServet</servlet-name>
<servlet-class>org.apache.struts.tiles.TilesServlet</servlet-class>
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
Pay attention to the load-on-startup tag. Tiles Servlet should be loaded after the Faces Servlet. It is important.

2. tiles-defs.xml file is a standard Tiles definitions file. You can use several of them. Use comma separated string to define such files for the definitions-config.

3. Use flush="false" for the tiles:insert tag is you use it inside the f:view

4. Use f:subview if you use tiles inside the f:facet. For example:
Code:
<f:facet name="header">
<f:subview id="header">
<tiles:insert definition="page.header" flush="false"/>
</f:subview>
</f:facet>

5. Never include f:view inside another f:view

6. You cannot forward directly to the tiles, like in the Struts. So, anyway, the faces-config file should contain a pages as a view.

No comments:

Post a Comment