On 12-01-23 01:00 PM, MiB wrote:
Yes, I'm using UrlBasedViewResolver this way:
***webmvc-config.xml***
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"
id="tilesViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
Once you know that, there are easy ways of putting the data into a
tiles attribute, and then you can use that attribute in your JSP with
<tiles:insertAttribute> or <tiles:importAttribute> as you like.
While I can use attributes in my jspx files, my view resolver is only
changing the main content tiles primary and secondary in my earlier
sample and the needed changes are in other tiles, ie "header" and also
within the head element which is only within my main template
"default.jspx".
The TilesView just uses the spring-provided view name as the name of the
definition to be processed. So the "current view" as seen from Tiles is
the current definition.
With Tiles 2.1 and above, you can use wildcards to put a part of a
definition's name into an attibute:
http://tiles.apache.org/2.2/framework/tutorial/advanced/wildcard.html
By default, Spring uses the request path as the view name, so usually
people use it as the definition name, too. For instance you could use:
<definition name="default" template="/WEB-INF/layouts/default.jspx">
<put-attribute name="header" value="/WEB-INF/views/header.jspx" />
<put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />
<!-- we need the "section" attribute, too, but just define it in
subclasses -->
</definition>
<definition name="/*/index" extends="default">
<put-attribute name="primary" value="/WEB-INF/views/primary.jspx" />
<put-attribute name="secondary"
value="/WEB-INF/views/secondary.jspx" />
<!-- whatever matches the * in the definition name -->
<put-attribute name="section" value="{1}"/>
</definition>
and then in your header.jspx (I'm assuming it's a navigation menu):
<!-- import the definition attribute into page scope for EL />
<tiles:importAttribute name="section" />
<ul id="navigation">
<li id="start" class="${section=='start'?'current':'menuentry'}"><a
href="/">Start</a></li>
<!-- More list items -->
</ul>
The <li> element receives the class 'current' in /start/index, but the
class 'menuentry' in /other/index.
Of course you can use another naming scheme if you prefer, like
"index-*" instead of "/*/index". It just has to fit whatever view names
you provide from the controller.
If you don't want to use EL expressions like
${section=='start'?'current':'menuentry'}, or if you need a more
complicated logic, you may use a ViewPreparer like Antonio said. Within
a preparer you can manipulate definition attributes and request
attributes as you want.
Hope this helps.
Nick