Home

 

Enabling the Struts Tiles support

In our prior example, when creating a Dynamic Web project, we did not enable Struts Tiles in the Web project.

To enable the support, right-click the RAD75StrutsWeb project and select Properties. In the Properties dialog, select Project Facets, select Dynamic Page Template Support (Struts Tiles), and click OK. This action creates the Tiles configuration and updates the Struts configuration to use Tiles. In addition, a TilesServlet is added to the Web deployment descriptor.

The Tiles configuration file (tiles-def.xml) is created under WebContent/WEB-INF, and it has no definitions yet. In addition, the struts-config.xml file is updated with a plug-in configuration (Example | 5-8).

Example 15-8 Plug-in configuration for Tiles in struts-config.xml file

<plug-in className="org.apache.struts.tiles.TilesPlugin">
	<set-property property="definitions-config"
					 value="/WEB-INF/tiles-defs.xml"/>
	<set-property property="definitions-parser-validate" value="true"/>
	<set-property property="moduleAware" value="true"/>
</plug-in>

There is also another piece of configuration that you have to put in manually. In the struts-config.xml, after the <action-mappings> section, insert the line shown in Example | 5-9.

Example 15-9 Controller configuration for Tiles

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" />

As a reference, these two entries in the struts-config.xml informs Struts that Tiles is used in this Web application. Specifically, we can now use ActionForward to forward control onto a Tiles configuration (among other things).

Note: Ignore the errors that are listed in the Problems view. This is a known defect that will be fixed in an upcoming FixPack. You can disable the Struts validator in the project Properties, Validation tab, clear Struts Configuration File Validator, and rebuild (clean) the project.

ibm.com/redbooks