Announcement Announcement Module
Collapse
No announcement yet.
Tiles 2 AND Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles 2 AND Spring MVC

    Hi alll,

    I dont understand how i can implements my controller : for the url :http://localhost/index.do



    My springapp.servlet.xml :
    Code:
    <!-- MVC annotated  -->
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    	<context:component-scan base-package="com.mfg.web" />
    
    
    	<bean id="tilesConfigurer"
    		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/tiles-defs/templates.xml
    				</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="viewResolver"
    		class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
    		<property name="prefix" value="/WEB-INF/jsp/" />
    		<property name="suffix" value=".jsp" />		
    	</bean>
    My tiles template:
    Code:
    <tiles-definitions>
    
        <!-- Default Main Template -->
        <definition name=".mainTemplate" template="/WEB-INF/templates/main.jsp">
            <put-attribute name="title" value="Pulse" type="string" />
            <put-attribute name="header" value="/WEB-INF/templates/header.jsp" />
            <put-attribute name="footer" value="/WEB-INF/templates/footer.jsp" />
            <put-attribute name="menu" value="/WEB-INF/templates/menu.jsp" />
            <put-attribute name="content" value="/WEB-INF/templates/blank.jsp" />
        </definition>
     
    
    </tiles-definitions>
    My Controller :
    Code:
    @Controller
    public class MainController {
    
    	protected final Log logger = LogFactory.getLog(getClass());
    
    	@RequestMapping("/index.do")
    	public ModelAndView displayrfq(HttpServletRequest request,
    			HttpServletResponse response) throws ServletException, IOException {
    
    		
    		// Create Model
    		String now = (new java.util.Date()).toString();
    		logger.info("returning hello view with " + now);
    		Map<String, Object> myModel = new HashMap<String, Object>();
    		myModel.put("now", now);
    
    		// create tile view
    		TilesView tilesView = new TilesView();		
    		tilesView.setBeanName("index");
    		return new ModelAndView(tilesView, "model", myModel);
    
    	}
    }

    what s wrong in my code : i want to display in tiles:content.


    --
    Julien

  • #2
    1) Shouldn't your viewResolver be the Tile2 resolver?
    2) Where is your URL to View mapping?
    3) localhost:index.do isn't right. Wouldn't that be http://localhost/someproject/index.do

    Comment


    • #3
      1) ok i ve put this :

      Code:
      <!-- MVC annotated  -->
      	<bean
      		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
      	<bean
      		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
      	<context:component-scan base-package="com.mfg.web" />
      
      	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
      	  <property name="definitions">
      	    <list>
      	      <value>/WEB-INF/tiles-def/templates.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"/>
      	</bean>

      2) URL to View mapping is annotated in the controller @RequestMapping("/index.do")

      3) it is http://localhost/index.do

      Comment


      • #4
        Hi all,

        in my controller :
        Code:
        @Controller
        public class MainController {
        
        	protected final Log logger = LogFactory.getLog(getClass());
        
        	@RequestMapping("/index.do")
        	public ModelAndView displayrfq(HttpServletRequest request,
        			HttpServletResponse response) throws ServletException, IOException {
        
        		
        		// Create Model
        		String now = (new java.util.Date()).toString();
        		logger.info("returning hello view with " + now);
        		Map<String, Object> myModel = new HashMap<String, Object>();
        		myModel.put("now", now);
        
        		// create tile view
        		TilesView tilesView = new TilesView();		
        		tilesView.setBeanName("index");
        		return new ModelAndView(tilesView, "model", myModel);
        
        	}
        }

        How can I define the view to be the tiles content (see my tiles definitions)?

        Comment


        • #5
          Here is what I used. In the servlet.xml:

          Code:
          	<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
          	  <property name="basename" value="views"/>
          	</bean>
          Then in the view.properties file in the classpath:

          Code:
          welcome.class=org.springframework.web.servlet.view.tiles2.TilesView
          welcome.url=.welcome
          Then in my annotated controler:

          Code:
          	@RequestMapping("/welcome.htm")
          	public String welcome(){
          
          
          		return "welcome";
          	}

          And of course in the tiles.xml:

          Code:
            	<definition name=".welcome" extends="main">
                	<put-attribute name="body" value="/WEB-INF/jsp/public/home.jsp"/>
            	</definition>

          Hope that helps.

          Comment


          • #6
            Hi,
            thamks for your reply,

            applicationContext.xml :
            Code:
            <bean id="tilesConfigurer"
            		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
            		<property name="definitions">
            			<list>
            				<value>/WEB-INF/tiles-def/templates.xml
            				</value>
            			</list>
            		</property>
            	</bean>
            
            	<bean id="viewResolver"
            		class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
            		<property name="basename" value="views" />
            	</bean>
            views.properties (in my classpath) :
            Code:
            welcome.class=org.springframework.web.servlet.view.tiles2.TilesView
            welcome.url=.welcome
            my controller :
            Code:
            @RequestMapping("/welcome.do")
            	public String welcome(){
            
            
            		return "welcome";
            	}
            my template :
            Code:
            <tiles-definitions>
            
                <!-- Default Main Template -->
                <definition name=".mainTemplate" template="/WEB-INF/templates/main.jsp">
                    <put-attribute name="title" value="Pulse" type="string" />
                    <put-attribute name="header" value="/WEB-INF/templates/header.jsp" />
                    <put-attribute name="footer" value="/WEB-INF/templates/footer.jsp" />
                    <put-attribute name="menu" value="/WEB-INF/templates/menu.jsp" />
                    <put-attribute name="content" value="/WEB-INF/templates/blank.jsp" />
                </definition>
                
             	<definition name=".welcome" extends="mainTemplate">
                  	<put-attribute name="content" value="/WEB-INF/jsp/home.jsp"/>
              	</definition>
                
            </tiles-definitions>
            BUT i ve :
            Code:
            Caused by: org.apache.tiles.definition.NoSuchDefinitionException: .welcome
            	at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:612)
            	at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:307)
            	at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:75)
            	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
            	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
            	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
            	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
            	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
            	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
            	at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
            	at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
            	at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
            	at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
            	at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:52)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:109)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
            	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
            	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
            	at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
            	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
            	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
            	at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
            	at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
            	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:266)
            	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
            	at com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
            	at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
            	at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
            	at java.lang.Thread.run(Thread.java:619)

            it s always the same since yesterday:

            any idea?

            Comment


            • #7
              it s looks my template is not red.
              Code:
              <bean id="tilesConfigurer"
              		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
              		<property name="definitions">
              			<list>
              				<value>/WEB-INF/tiles-def/templates.xml
              				</value>
              			</list>
              		</property>
              	</bean>
              ??

              Comment


              • #8
                I've get following exception:
                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)

                Comment

                Working...
                X