Results 1 to 8 of 8

Thread: Spring & Tiles

  1. #1
    Join Date
    Oct 2004
    Location
    South Africa
    Posts
    5

    Default Spring & Tiles

    Hi

    I'm having a bit of a weird problem with Spring and Tiles. Basically my page is divided into a header, a thinish side bar and the main area. Now my first page loads perfectly in the main area. However when I click on a link to the next page it loads only on the right hand side of the main area, as if the main area is divided exactly down the middle.

    I know its a silly mistake on my side but can't figure it out as I click on a link to the first page and that loads fine!

    This is the layout specified for each page: (template.jsp)


    Code:
    <%@ taglib prefix="tiles" uri="http&#58;//jakarta.apache.org/struts/tags-tiles" %>
    <html>
    	<head>
    		<title>Pete's Pet Store</title>
    	</head>
    	<body bgcolor="lightblue">
    		<table width="100%" border="0">
    			<tr>
    				<td colspan="2" valign="middle"><tiles&#58;insert name="topbar"/></td>
    			</tr>
    			<tr>
    				<td width="180" valign="top">
    					<tiles&#58;insert name="sidebar"/>
    				</td>
    				<td valign="top">
    					<tiles&#58;insert name="main"/>
    				</td>
    			</tr>
    		</table>
    	</body>
    </html>
    This is my tiles-defs.xml:
    Code:
    <tiles-definitions>
    
    	<!-- DEFAULT MAIN TEMPLATE -->
    	<definition name="template" page="/WEB-INF/jsp/template.jsp">
    	    <put name="topbar" value="/WEB-INF/jsp/topbar.jsp"/>
    		<put name="sidebar" value="/WEB-INF/jsp/sidebar.jsp"/>
    	</definition>
    
    	<definition name="index" extends="template" path="/WEB-INF/jsp/template.jsp">
    		<put name="main" value="/WEB-INF/jsp/hello.jsp"/>
    	</definition>
    	
    	<definition name="menu" extends="template" path="/WEB-INF/jsp/template.jsp">
    		<put name="main" value="/WEB-INF/jsp/menu.jsp"/>
    	</definition>
    
    </tiles-definitions>
    This is the page that is causing all the problems! (menu.jsp)
    Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <html>
    <head><title><fmt&#58;message key="hello.title"/></title></head>
    <body>
    
    <h3><c&#58;out value="$&#123;model.menuname&#125;"/></h3>
    
    <br>
    <c&#58;forEach items="$&#123;model.menuitems&#125;" var="item">
    <img src="image/paw.jpg" align="absmiddle"><a href="<c&#58;url value="$&#123;item.url&#125;"/>"><c&#58;out value="$&#123;item.description&#125;"/></a><br>
    </c&#58;forEach>
    </body>
    </html>
    But this is the page that is fine:
    Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <html>
    <head><title><fmt&#58;message key="hello.title"/></title></head>
    <body>
    
    <h1><fmt&#58;message key="hello.heading"/></h1>
    
    
    <h3><fmt&#58;message key="hello.products"/></h3>
    <c&#58;forEach items="$&#123;model.products&#125;" var="prod">
      <c&#58;out value="$&#123;prod.description&#125;"/> <i>$<c&#58;out value="$&#123;prod.price&#125;"/></i><br><br>
    </c&#58;forEach>
    <br>
    <a href="<c&#58;url value="priceincrease.htm"/>"><fmt&#58;message key="hello.increaselink"/></a>
    <br>
    </body>
    </html>
    Please excuse my complete newbieness! Any help would be appreciated!

    Thanks
    Kim

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Remove the path attribute from these definitions:
    Code:
       <definition name="index" extends="template"> 
          <put name="main" value="/WEB-INF/jsp/hello.jsp"/> 
       </definition> 
        
       <definition name="menu" extends="template"> 
          <put name="main" value="/WEB-INF/jsp/menu.jsp"/> 
       </definition>
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Oct 2004
    Location
    South Africa
    Posts
    5

    Default

    Hi

    Thanks very much for the suggestion. I tried removing the paths but it still has the same problem. If I copy the gut of hello.jsp into menu.jsp it displays fine so I think it might be something in the actual menu.jsp code rather than the mappings. It's all very confusing to me!

    Kim

  4. #4
    Join Date
    Oct 2004
    Location
    South Africa
    Posts
    5

    Default

    Please if anyone has any more input on this topic I'd really appreciate it. I'm really stumped. :shock:

    Thanks
    Kim

  5. #5
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Could you send me a sample that reproduce this issue off-line?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  6. #6
    Join Date
    Sep 2004
    Posts
    50

    Default

    try adding type="page"

    so you end up with

    <put name="main" value="/WEB-INF/jsp/menu.jsp" type="page"/>

    in your tiles definition file

  7. #7

    Default

    I have been using Spring MVC with Tiles for a couple of projects with any issues so far.

    You define two dynamic regions in your template. When you extend your template, you need provide your definition for the both regions. You don't do so. That is the reason you screw up your JSP file, I guess. You can verify it with the Tiles document.

    If you know the definition of an abstract class, you might think a template as an abstract class. To instance it, you need to extend the class with all method implemented. To put a template in use, you need to provide all portions for the template.

  8. #8
    Join Date
    Dec 2008
    Location
    Ulaanbaatar, Mongolia
    Posts
    123

    Default

    Hi there. I got following exception.
    I'm newbie and don't know what's wrong.
    Code:
    java.lang.NullPointerException
    	at org.apache.struts.taglib.tiles.InsertTag.processName(InsertTag.java:527)
    	at org.apache.struts.taglib.tiles.InsertTag.createTagHandler(InsertTag.java:482)
    	at org.apache.struts.taglib.tiles.InsertTag.doStartTag(InsertTag.java:438)
    	at org.apache.jsp.index_jsp._jspx_meth_tiles_005finsert_005f0(index_jsp.java:151)
    	at org.apache.jsp.index_jsp._jspService(index_jsp.java:99)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Unknown Source)
    Here's the web.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    	<description>
    		Tiles and Spring
    	</description>
    	<display-name>TaS</display-name>
    	<icon>
    		<small-icon>/images/icon-small.gif</small-icon>
    		<large-icon>/images/icon-large.gif</large-icon>
    	</icon>
    	<servlet>
    		<description>dispatcher servlet</description>
    		<display-name>Test DWR</display-name>
    		<servlet-name>test-dwr</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>classpath:applicationContext.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderServlet</listener-class>
    	</listener>
    	<servlet-mapping>
    		<servlet-name>test-dwr</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    	<error-page>
    		<error-code>404</error-code>
    		<location>/error.jsp</location>
    	</error-page>
    	<error-page>
    		<exception-type>java.lang.Exception</exception-type>
    		<location>/error.jsp</location>
    	</error-page>
    	<error-page>
    		<exception-type>org.hibernate.HibernateException</exception-type>
    		<location>/error.jsp</location>
    	</error-page>
    </web-app>
    Here's the tas-tiles.xml file:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE tiles-definitions PUBLIC
     "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
     "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
    
    <tiles-definitions>
    	<definition name=".header" page="/header.jsp"
    		controllerClass="com.eon.controller.HeaderTileController" />
    
    	<definition name="template" page="/index.jsp">
    		<put name="title" value="Tiles and Spring" />
    		<put name="header" value="/header" />
    		<put name="content" value="/indexcontent.jsp" />
    		<put name="footer" value="/footer.jsp" />
    	</definition>
    </tiles-definitions>
    Here's the applicationContext.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    	http://www.directwebremoting.org/schema/spring-dwr
    	http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">
    
    	<bean id="simpleHandler"
    		class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<bean id="throwawayHandler"
    		class="org.springframework.web.servlet.mvc.throwaway.ThrowawayControllerHandlerAdapter" />
    
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    		<property name="order" value="1" />
    	</bean>
    
    	<bean
    		class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    		<property name="order" value="2" />
    	</bean>
    
    	<bean id="urlMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="index.htm">indexController</prop>
    				<!--
    					<prop key="messages.htm">messagesController</prop> <prop
    					key="sendmessage.htm">sendMessageController</prop>
    				-->
    			</props>
    		</property>
    	</bean>
    
    	<bean id="viewNameTranslator"
    		class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" />
    
    	<bean id="tilesConfigurer"
    		class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/tas-tiles.xml</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    		p:prefix="" p:suffix=".jsp">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.tiles.TilesJstlView" />
    	</bean>
    
    	<bean name="indexController"
    		class="org.springframework.web.servlet.mvc.ParameterizableViewController"
    		p:viewName="index" />
    
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="alwaysUseFullPath" value="true" />
    		<property name="mappings">
    			<props>
    				<prop key="/dwr/**/*">dwrController</prop>
    				<prop key="/dwr/*">dwrController</prop>
    			</props>
    		</property>
    	</bean>
    
    	<dwr:controller id="dwrController" debug="true" />
    
    	<dwr:configuration />
    
    	<bean id="hibernateSF"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="configLocation" value="classpath:hibernate.cfg.xml">
    		</property>
    	</bean>
    </beans>
    What's wrong with this?

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 1
    Last Post: Oct 21st, 2005, 05:27 AM
  3. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  4. Replies: 2
    Last Post: Feb 10th, 2005, 03:17 PM
  5. More Spring & Tiles examples/tutorials?
    By michael in forum Web
    Replies: 1
    Last Post: Dec 5th, 2004, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •