Announcement Announcement Module
Collapse
No announcement yet.
Tiles integration in spring 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles integration in spring 3

    Hi,
    I am using spring 3.0.5 and tiles 2.2.2. I have configured tiles as mentioned in http://viralpatel.net/blogs/2010/07/...e-eclipse.html

    There is slight twist in my requirement. I want that all the jsp's to use the template configured in dispatcher-servlet.xml
    i.e all my msp's are to be mapped with tiles defn as below

    Code:
    <definition name="baseLayout" template="/jsp/tiletemplate/baseLayout.jsp">
    <put-attribute name="header" value="/jsp/tiletemplate/tiles/header.jsp" />
    <put-attribute name="body" value="" />
    <put-attribute name="footer" value="/jsp/tiletemplate/tiles/footer.jsp" />
    </definition>
    How can i do it ? i tried running my configured application and i get exception javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'dispatcher'

    below is my stacktrace
    Code:
    javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'saas'
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    tiles-template-2.2.2.jar, tiles-servlet-wildcard-2.2.2.jar, tiles-servlet-2.2.2.jar, tiles-jsp-2.2.2.jar, tiles-core-2.2.2.jar, tiles-api-2.2.2.jar are the jar files used

    any help will be highly appreciated

  • #2
    For starters post some configuration, next tell a consistent story... Your servlet isn't named 'dispatcher' it is named 'saas' if you have multiple servlets and trying to use multiple tiles instances that isn't going to work. Also you still need to have a definition called 'index' in our tiles definition and it needs to extend the 'baseLayout'.

    Comment


    • #3
      My appologies,
      It is actually saas-servlet and not dispatcher servlet
      Below is my configuration
      Code:
      	<bean id="tilesConfigurer"
      		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
      		<property name="definitions">
      			<list>
      				<value>/WEB-INF/tiles.xml</value>
      			</list>
      		</property>
      
      	</bean>
      
      <bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver">
          <property name="viewClass">
              <value>
                  org.springframework.web.servlet.view.tiles2.TilesView
              </value>
          </property>
      </bean>
      My tiles. xml
      Code:
      <tiles-definitions>
          <definition name="base.definition"
              template="/jsp/tiletemplate/baseLayout.jsp">
              <put-attribute name="header" value="/jsp/tiletemplate/tiles/header.jsp" />
              <put-attribute name="body" value="" />
              <put-attribute name="footer" value="/jsp/tiletemplate/tiles/footer.jsp" />
          </definition>
              <definition name="index" extends="base.definition">
            <put-attribute name="body" value="*.jsp" />
          </definition>
       
       
      </tiles-definitions>
      I tried solving the error but now i get classcast exception
      Code:
      SEVERE: Servlet.service() for servlet [saas] in context with path [/latestcode] threw exception [Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/jsp/tiletemplate/baseLayout.jsp'.] with root cause
      java.lang.ClassCastException: org.apache.tiles.jsp.taglib.InsertAttributeTag cannot be cast to javax.servlet.jsp.tagext.Tag
      	at org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:117)
      	at org.apache.jsp.jsp.tiletemplate.baseLayout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(baseLayout_jsp.java:90)
      	at org.apache.jsp.jsp.tiletemplate.baseLayout_jsp._jspService(baseLayout_jsp.java:62)
      	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      I want to map all my jsp to the definition base.definition can we do it? Just a slight diversion question to ask if i need to have different attributes for somejsp / if i want to use different header template to some jsp's then can i do it? can you give me some link from where i can get any help

      Thanks and Regards

      Comment


      • #4
        I'm not that familair with Tiles but I doubt *.jsp would work. Also each view needs to be present as a definition (imho one of the drawbacks for tiles). You might be able to create something in spring which resolves to a default view when nothing is found by the view resolver (shouldn't be that hard).

        Judging from the stacktrace you have some issue with your classpath, make sure you don't include jars which are also provided by the container (apis and such). Also make sure you have all the proper tiles jars and that you are not mixing versions.

        Comment


        • #5
          You can use wildcards and path replacement in Tiles. If you had a tiles definition like this:

          Code:
          <tiles-definitions>
            <definition name="base.definition" template="/jsp/tiletemplate/baseLayout.jsp">
              <put-attribute name="header" value="/jsp/tiletemplate/tiles/header.jsp" />
              <put-attribute name="body" value="" />
              <put-attribute name="footer" value="/jsp/tiletemplate/tiles/footer.jsp" />
            </definition>
            
            <definition name="*" extends="base.definition">
              <put-attribute name="body" value="/jsp/views/{1}.jsp" />
            </definition>
          </tiles-definitions>
          then trying to resolve a view named "index" would result in Tiles looking for a file with the path "/jsp/views/index.jsp".

          You can have multiple wildcards and path replacements if you want more granularity and depth in your project structure, so a definition like:

          Code:
            <definition name="*/*" extends="base.definition">
              <put-attribute name="body" value="/jsp/views/{1}/{2}.jsp" />
            </definition>
          would map a view path of "auth/login" to "/jsp/views/auth/login.jsp".

          Comment


          • #6
            Ah.. Learned something in the process, thanks.

            Comment

            Working...
            X