WARNING!!! Configuration with initialization parameters is deprecated! If you still want to use it, please refer to 2.1 version of this page.
XML definition files can be loaded using wildcard, but this behaviour is not the default, due to compatibility reasons to Tiles 2.0.x.
To use wildcards in XML definition files, you need to put the following libraries in your classpath:
If you are using Maven, simply depend on spring-web package.
To be able to specify Tiles XML definition files using wildcards, there is the need to override the Tiles application context creation, by overriding the createTilesApplicationContext method this way:
@Override protected TilesApplicationContext createTilesApplicationContext( TilesApplicationContext preliminaryContext) { return new WildcardServletTilesApplicationContext( (ServletContext) preliminaryContext.getContext()); }
To load XML definition files using wilcards, override the getSourceURLs of BasicTilesContainerFactory. In the following example, notice the manual exclusion of files including underscores (_):
/** {@inheritDoc} */ @Override protected List<URL> getSourceURLs(Object context, TilesApplicationContext applicationContext, TilesRequestContextFactory contextFactory) { List<URL> urls = new ArrayList<URL>(URL_COUNT); try { Set<URL> urlSet = applicationContext .getResources("/WEB-INF/tiles-defs*.xml"); for (URL url : urlSet) { String externalForm = url.toExternalForm(); if (externalForm.indexOf('_', externalForm.lastIndexOf("/")) < 0) { urls.add(url); } } urls.add(applicationContext.getResource( "classpath:/org/apache/tiles/classpath-defs.xml")); } catch (IOException e) { throw new DefinitionsFactoryException( "Cannot load definition URLs", e); } return urls; }
Wildcard support uses Spring Framework syntax for loading files. For example:
For everything else, see Spring's documentation.