diff --git a/org.springframework.web.servlet/ivy.xml b/org.springframework.web.servlet/ivy.xml
index 988198590f5..7b198be68a8 100644
--- a/org.springframework.web.servlet/ivy.xml
+++ b/org.springframework.web.servlet/ivy.xml
@@ -52,11 +52,13 @@
conf="compile->compile"/>
The TilesConfigurer simply configures a TilesContainer using a set of files
- * containing definitions, to be accessed by {@link TilesView} instances.
+ * containing definitions, to be accessed by {@link TilesView} instances. This is a
+ * Spring-based alternative (for usage in Spring configuration) to the Tiles-provided
+ * {@link org.apache.tiles.web.startup.TilesListener} (for usage in web.xml).
*
*
TilesViews can be managed by any {@link org.springframework.web.servlet.ViewResolver}.
* For simple convention-based view resolution, consider using {@link TilesViewResolver}.
@@ -69,12 +72,12 @@ import org.springframework.web.context.ServletContextAware;
* </property>
* </bean>
*
- * The values in the list are the actual files containing the definitions.
+ * The values in the list are the actual Tiles XML files containing the definitions.
*
* @author Juergen Hoeller
* @since 2.5
* @see TilesView
- * @see org.springframework.web.servlet.view.UrlBasedViewResolver
+ * @see TilesViewResolver
*/
public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean {
@@ -86,24 +89,16 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
public TilesConfigurer() {
- this.tilesPropertyMap.put(
- TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM,
- TilesContainerFactory.class.getName());
- this.tilesPropertyMap.put(
- TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM,
- ChainedTilesContextFactory.class.getName());
- this.tilesPropertyMap.put(
- TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM,
- UrlDefinitionsFactory.class.getName());
- this.tilesPropertyMap.put(
- TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
+ this.tilesPropertyMap.put(AbstractTilesApplicationContextFactory.APPLICATION_CONTEXT_FACTORY_INIT_PARAM,
+ WildcardServletTilesApplicationContextFactory.class.getName());
+ this.tilesPropertyMap.put(TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
BasicPreparerFactory.class.getName());
- this.tilesPropertyMap.put(
- ChainedTilesContextFactory.FACTORY_CLASS_NAMES,
- ServletTilesContextFactory.class.getName() + "," + JspTilesContextFactory.class.getName());
- this.tilesPropertyMap.put(
- UrlDefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
+ this.tilesPropertyMap.put(DefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
SpringLocaleResolver.class.getName());
+ this.tilesPropertyMap.put(TilesContainerFactory.ATTRIBUTE_EVALUATOR_INIT_PARAM,
+ ELAttributeEvaluator.class.getName());
+ this.tilesPropertyMap.put(TilesContainerFactory.CONTAINER_FACTORY_MUTABLE_INIT_PARAM,
+ Boolean.toString(false));
}
@@ -117,7 +112,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
if (logger.isInfoEnabled()) {
logger.info("TilesConfigurer: adding definitions [" + defs + "]");
}
- this.tilesPropertyMap.put(BasicTilesContainer.DEFINITIONS_CONFIG, defs);
+ this.tilesPropertyMap.put(DefinitionsFactory.DEFINITIONS_CONFIG, defs);
}
}
@@ -190,24 +185,23 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
/**
- * Creates and exposes a TilesContainer for this web application.
+ * Creates and exposes a TilesContainer for this web application,
+ * delegating to the TilesInitializer.
* @throws TilesException in case of setup failure
+ * @see #createTilesInitializer()
*/
public void afterPropertiesSet() throws TilesException {
- TilesContainer container = createTilesContainer(this.servletContext);
- TilesAccess.setContainer(this.servletContext, container);
+ ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
+ createTilesInitializer().initialize(new ServletTilesApplicationContext(adaptedContext));
}
/**
- * Create a TilesContainer for this web application.
- * @param context this web application's ServletContext
- * @return the TilesContainer to expose
- * @throws TilesException in case of setup failure
+ * Creates a new instance of {@link org.apache.tiles.startup.BasicTilesInitializer}.
+ * Override it to use a different initializer.
+ * @see org.apache.tiles.web.startup.TilesListener#createTilesInitializer()
*/
- protected TilesContainer createTilesContainer(ServletContext context) throws TilesException {
- ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
- TilesContainerFactory factory = TilesContainerFactory.getFactory(adaptedContext);
- return factory.createContainer(adaptedContext);
+ protected TilesInitializer createTilesInitializer() {
+ return new BasicTilesInitializer();
}
/**
@@ -215,7 +209,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D
* @throws TilesException in case of cleanup failure
*/
public void destroy() throws TilesException {
- TilesAccess.setContainer(this.servletContext, null);
+ ServletUtil.setContainer(this.servletContext, null);
}
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
index d476874fe10..56d295862dc 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
@@ -16,14 +16,20 @@
package org.springframework.web.servlet.view.tiles2;
+import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.tiles.TilesApplicationContext;
import org.apache.tiles.TilesContainer;
-import org.apache.tiles.access.TilesAccess;
+import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.impl.BasicTilesContainer;
+import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
+import org.apache.tiles.servlet.context.ServletTilesRequestContext;
+import org.apache.tiles.servlet.context.ServletUtil;
import org.springframework.web.servlet.support.JstlUtils;
import org.springframework.web.servlet.support.RequestContext;
@@ -49,9 +55,21 @@ import org.springframework.web.util.WebUtils;
public class TilesView extends AbstractUrlBasedView {
@Override
- public boolean checkResource() throws Exception {
- TilesContainer container = TilesAccess.getContainer(getServletContext());
- return container.isValidDefinition(getUrl());
+ public boolean checkResource(final Locale locale) throws Exception {
+ TilesContainer container = ServletUtil.getContainer(getServletContext());
+ if (!(container instanceof BasicTilesContainer)) {
+ // Cannot check properly - let's assume it's there.
+ return true;
+ }
+ BasicTilesContainer basicContainer = (BasicTilesContainer) container;
+ TilesApplicationContext appContext = new ServletTilesApplicationContext(getServletContext());
+ TilesRequestContext requestContext = new ServletTilesRequestContext(appContext, null, null) {
+ @Override
+ public Locale getRequestLocale() {
+ return locale;
+ }
+ };
+ return (basicContainer.getDefinitionsFactory().getDefinition(getUrl(), requestContext) != null);
}
@Override
@@ -59,7 +77,7 @@ public class TilesView extends AbstractUrlBasedView {
Map