spring - Tiles 2 Access Variable in Template -
i using spring mvc framework apache tiles 2. want able have multiple controllers use same view (different logic, basic presentation). can easily. want have different tiles definitions each controller, using same jsp file, each passing different template variables (page header, short description, etc). tiles template definition file:
<tiles-definitions> <!-- default main template --> <definition name=".maintemplate" template="/web-inf/templates/main.jsp"> <put-attribute name="shorttitle" value="company abc" type="string" /> <put-attribute name="body" value="/web-inf/templates/blank.jsp" /> </definition> <!-- overriding templates --> <definition name="index" extends=".maintemplate"> <put-attribute name="title" value="company alpha bravo charlie" type="string" /> <put-attribute name="body" value="/web-inf/views/index.jsp" /> </definition> <definition name="index2" extends=".maintemplate"> <put-attribute name="title" value="company other page" type="string" /> <put-attribute name="body" value="/web-inf/views/index.jsp" /> </definition> </tiles-definitions>
i try have /web-inf/views/index.jsp
:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %> <h1> hello world, it's <tiles:getasstring name="title" />! </h1>
when load tomcat , bring page, long stack trace of exceptions. top of pile says org.apache.tiles.impl.cannotrenderexception: servletexception including path '/web-inf/templates/main.jsp'.} root cause org.apache.tiles.template.nosuchattributeexception: attribute 'title' not found
. know what's going on?
i try have /web-inf/views/index.jsp:
how try this? in controller specify name of tiles view, not 1 of multiple jsp tiles use in order render page:
@requestmapping("index2") public string index2() { // ... return "index2"; }
Comments
Post a Comment