So I have been using a hack to get rid of the lame views.properties file for about 6 years now. Here is my amazing solution for all of you to laugh at/use:
Define your viewResolver this way instead
<bean id="viewResolver" class="com.yourcompany.util.TilesResourceBundleViewResolver"/>
Here is the implementation of the resolver that looks directly at your tiles views
package com.yourcompany.util;
import java.util.Locale;
import java.util.MissingResourceException;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.tiles.DefinitionsFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContextException;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.tiles.TilesView;
import org.apache.struts.tiles.DefaultTilesUtilImpl;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.servlet.view.AbstractCachingViewResolver;
/**
* Dave's improved view resolver because he hates having too many files to
* update every time he creates a new view. Spring already makes it bad enough!
*
* @author dave
*/
public class TilesResourceBundleViewResolver extends AbstractCachingViewResolver
{
private final String CONTENT_TYPE = "text/html;charset=utf-8";
/**
* for some incomprehensible reason the tiles stuff requires an http request
* in order to see if a view exists.
*/
private static final HttpServletRequest FAKE_HTTP_REQUEST =
new MockHttpServletRequest();
@Override
protected View loadView(String viewName, Locale locale) throws
MissingResourceException, BeansException, Exception
{
// check if the view is defined
// in the site-views.xml and let tiles worry about it
DefinitionsFactory definitionsFactory =
(DefinitionsFactory) getServletContext().getAttribute(
DefaultTilesUtilImpl.DEFINITIONS_FACTORY);
if (definitionsFactory == null)
{
throw new ApplicationContextException(
"Tiles definitions factory not found: TilesConfigurer not defined?");
}
if (definitionsFactory.getDefinition(viewName,
FAKE_HTTP_REQUEST, getServletContext()) == null)
{
//log.warn("Request for unknown view: " + viewName);
viewName = "PageNotFound";
}
TilesView t = new TilesView();
t.setBeanName(viewName);
t.setUrl(viewName);
t.setApplicationContext(getApplicationContext());
t.setContentType(CONTENT_TYPE);
return t;
}
}