Announcement Announcement Module
Collapse
No announcement yet.
Integrate TILES in Spring 3.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integrate TILES in Spring 3.0

    Hi, I'm new to spring and I'm trying to use Tiles: but I have this error :

    Etat HTTP 500 - Could not resolve view with name 'security/login_form' in servlet with name 'actions'


    My config is :

    tiles.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE tiles-definitions PUBLIC
           "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
           "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
    <tiles-definitions>
    	<definition name="base.definition" template="/WEB-INF/jsp/layout.jsp">
    		<put-attribute name="title" value="" />
    		<put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
    		<put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
    		<put-attribute name="body" value="" />
    		<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
    	</definition>
    	<definition name="login" extends="base.definition">
    		<put-attribute name="title" value="Authentication" />
    		<put-attribute name="body" value="/resources/pages/security/login_form.jsp" />
    	</definition>
    </tiles-definitions>
    actions-servlet.xml

    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:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    	<mvc:annotation-driven />
    	<context:annotation-config />
    	<context:component-scan base-package="fr.spring.controller" />
    
    	<!-- 
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    		<property name="prefix" value="/resources/pages/" /> 
    		<property name="suffix" value=".jsp" /> 
    	</bean> -->
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass">
    			<value>
    				org.springframework.web.servlet.view.tiles2.TilesView
    			</value>
    		</property>
    		<property name="prefix" value="/resources/pages/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
    	<bean id="tilesConfigurer"
    		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/tiles.xml</value>
    			</list>
    		</property>
    	</bean>
    </beans>
    Controller
    Code:
    package fr.spring.controller;
    
    import java.security.Principal;
    
    import java.security.Principal;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    
    @Controller
    public class ControllerExamplesSecurity {
    
    
    	@RequestMapping(value="/welcome", method = RequestMethod.GET)
    	public String printWelcome(ModelMap model, Principal principal ) {
     
    		String name = principal.getName();
    		model.addAttribute("username", name);
    		model.addAttribute("message", "Spring Security Custom Form example");
    		return "security/welcome";
    	
    	}
     
    	@RequestMapping(value="/login", method = RequestMethod.GET)
    	public String login(ModelMap model) {
     
    		System.out.println("test tiles");
    		return "security/login_form";
     
    	}
    	
    	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
    	public String loginerror(ModelMap model) {
     
    		model.addAttribute("error", "true");
    		return "security/login_form";
     
    	}
    	
    	@RequestMapping(value="/logout", method = RequestMethod.GET)
    	public String logout(ModelMap model) {
     
    		return "security/login_form";
     
    	}
    	
    }
    Attachment
    Attached Files
    Last edited by minzou; May 21st, 2013, 10:25 AM.

  • #2
    And why should it work... To work with tiles you need the TilesViewResolver not the UrlBasedViewResolver... I suggest a read of the reference guide which explains what to use.

    Comment


    • #3
      Thank you but i resolved the problem: i just have changed name="login" -> name="security/login_form"

      Comment


      • #4
        That doesn't resolve your problem. YOu are now basically NOT using tiles.

        You should be using the view named 'login' (that is the name of your tiles definitin). This will only work if you use the correct viewresolver.

        Again read the reference guide which explains the integration.
        Last edited by Marten Deinum; May 24th, 2013, 05:15 AM.

        Comment


        • #5
          i'm using this config and it's work

          Code:
          <bean id="viewResolver"
          		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
          		<property name="viewClass">
          			<value>
          				org.springframework.web.servlet.view.tiles2.TilesView
          			</value>
          		</property>
          	</bean>
          	<bean id="tilesConfigurer"
          		class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
          		<property name="definitions">
          			<list>
          				<value>/WEB-INF/tiles.xml</value>
          			</list>
          		</property>
          	</bean>

          Comment


          • #6
            No it doesn't... It appears to work, as mentioned you are basically bypassing Tiles and the ability to use definition names as view name. YOu are simply refering to a JSP instead of a Tiles definition.

            Again configure the TilesViewResolver instead of the UrlBasedViewResolver and use the 'login' as the view name.

            Comment

            Working...
            X