tiles2 definition not working with ControllerClassNameHandlerMapping
I'm using ControllerClassNameHandlerMapping to avoid explicitly mapping URLs to controllers, and so far it works fine. I have a link in index.jsp to welcome.html, which is properly mapped to welcomeController, which contains the following:
setCommandClass(User.class);
setCommandName("user");
setSuccessView("homeView");
setFormView("welcomeView");
The problem is that when I try to add a tile in tiles.xml definition with that URL like this:
<definition name="welcome" extends="开发者_StackOverflowbase.definition">
<put-attribute name="title" value="Welcome!"/>
<put-attribute name="body" value="/WEB-INF/jsp/welcomeView.jsp"/>
</definition>
The only tiles bean i declared within dispatcher-servlet.xml is:
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
I've tried many permutations with the tiles.xml file so far with no success. The view is loaded correctly, i get no errors in console, but tiles is nowhere to be seen. What am i missing?
Thanks in advance (:
It looks like you may not have a ViewResolver
for tiles configured. From the documentation
To be able to use the views you have to have a ViewResolver
just as with any other view technology used with Spring.
You can choose between UrlBasedViewResolver
and ResourceBundleViewResolver
.
It looks like currently it is resolving the view name (welcomeView
) to the corresponding jsp (welcomeView.jsp
) and thus you are not getting the tiles.
I have view resolver declared as follows
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"
p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView"
/>
精彩评论