views:

26

answers:

1

I have been trying to render tiles view with UrlBasedViewResolver for hours. Can anybody show me how it's done. I generally am trying to work this out

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"></property>
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
    <property name="order" value="1"/>              
</bean> 


<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename" value="views"/>
    <property name="order" value="0"/>
</bean>

and in my views.properties file, I would have my other view paths which would be rendered by jstlView. here is the exception it's giving

javax.servlet.ServletException: Could not resolve view with name 'welcome' in servlet with name 'epub'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1042)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

this just wouldn't work though. It says that it can't render the view. I know it's not because of chaining 2 view resolvers and not because of tiles conf either. Because when I define tile's view class in view.properties file it would work. So I assume that urlbasedviewresolver and tilesview can't work together in some ways. I will have a lot of tile layouts so it's not really beautiful to define all of them in my properties file.(I will have few regular jsp pages so it's ok to use resourceBundleViewResolver) Any ideas?

A: 

Here goes what you need to set up Tiles (I suppose you are using Tiles 2)

1º step

Define a TilesConfigurer

<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <!--Set up your Tiles definition RIGHT HERE-->    
            <value>/WEB-INF/defs/general.xml</value>
        </list>
    </property>
</bean>

2º step

Set up your view resolver (You can use Either UrlBasedViewResolver Or ResourceBundleViewResolver). But keep in mind whether you use UrlBasedViewResolver, Spring does not allow you use other UrlBasedViewResolver subclass, such as InternalResourceView, VelocityView and FreeMarkerView.

Either

<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <!--Tiles IS NOT JSP-->
    <!--So you can not use JSP stuffs like .jsp suffix-->
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>

Or

<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <!--views.properties is located in The root of the classpath-->
    <property name="basename" value="views"/>
</bean>

Here goes some piece of code of view.properties

#You MUST SET UP each Target view class
welcome.(class)=org.springframework.web.servlet.view.tiles2.TilesView
#url MUST MATCH Tiles definition 
welcome.url=welcome
Arthur Ronald F D Garcia
Tnx, So I can not use suffix and prefix. And I removed suffix prefix part and it worked like a charm. I don't know why I didn't try that b4. I used ResourceBundleViewResolver for my jsp pages(I am going to have very few jsp page) and UrlBasedViewResolver for my tiles. You saved my day. Thank you very much Arthur!
gun-armod