java - Spring 3 with Tiles 2.2 - Templates don't show -
i newbie @ spring 3 , tiles 2.2.2. next spring documentation on http://static.springsource.org/spring/docs/3.0.x/reference/view.html configure tiles templates don't show @ test page.
here web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="webapp_id" version="2.5"> <display-name>livros</display-name> <welcome-file-list> <welcome-file>formulario-login.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>setcharacterencodingfilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf8</param-value> </init-param> <init-param> <param-name>forceencoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>setcharacterencodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
... spring-context.xml
<mvc:annotation-driven /> <mvc:resources location="/resources/" mapping="/resources/**"/> <mvc:default-servlet-handler/> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="viewresolver" class="org.springframework.web.servlet.view.resourcebundleviewresolver"> <property name="basename" value="views"/> </bean> <mvc:interceptors> <bean class="br.com.coldsoft.livros.interceptor.autorizadorinterceptor" /> </mvc:interceptors> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer"> <property name="definitions"> <list> <value>/web-inf/tiles-defs.xml</value> </list> </property> </bean> </beans>
tiles-defs.xml
<?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="layout" template="/web-inf/templates/layout.jsp"> <put-attribute name="title" value="controle de livros" /> <put-attribute name="menu" value="/web-inf/templates/menu.jsp" /> <put-attribute name="body" value="/web-inf/templates/body.jsp" /> <put-attribute name="footer" value="/web-inf/templates/footer.jsp" /> </definition> <definition name="main" extends="layout"> <put-attribute name="title" value="main"></put-attribute> <put-attribute name="body" value="/web-inf/views/main.jsp"></put-attribute> </definition> </tiles-definitions>
layout.jsp
<html> <head> <!-- titulo controle de livros --> <title><tiles:insertattribute name="title" ignore="true" /></title> </head> <body> <tiles:insertattribute name="menu" /> <tiles:insertattribute name="body" /> <tiles:insertattribute name="footer" /> </body> </html>
views.properties
main.(class)=org.springframework.web.servlet.view.tiles2.tilesview main.url=main
when access http://myserver:8080/livros/main
shows content of main.jsp
<div class="container"> <h3>bem vindo, ${usuariologado.login}!!!!!!!!!!!!!!!!</h3> </div>
how can show templates have created on layout.jsp (they @ web-inf/templates) ??
please help me out!!
replace viewresolver
by:
<bean class="org.springframework.web.servlet.view.urlbasedviewresolver" id="tilesviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.tiles2.tilesview" /> </bean>
and remove internalresourceviewresolver
java spring tiles
No comments:
Post a Comment