Wednesday September 24, 2003
Tiles Tips o' the Day Here's a couple of things I learned today that might be useful to you Struts developers out there. When using Tiles, you'll normally import all the attributes into your baseLayout.jsp, and then your attributes are exposes as beans/scripting variables (you can actually grab them with JSTL tags). Rather than using:
<tiles:importAttribute/>
Use:
<tiles:importAttribute scope="request"/>
And then all your inserted pages can access these attributes. Pretty slick when you got a little JSTL love in the mix. The second tip is how to implement definition path switching. Let's look at the following baseLayout definition as an example:
<definition name=".baseLayout" path="/layouts/baseLayout.jsp">
<put name="titleKey"/>
<put name="header" value="/common/header.jsp"/>
<put name="sidebar" value=".sidebar"/>
<put name="footer" value="/common/footer.jsp"/>
</definition>
You currently cannot change the "path" attribute with a Controller, so you have to do it as the Tiles author recommends - by changing your path to refer to an action. So I changed the path on this particular definition to be:
<definition name=".baseLayout" path="/do/switchLayout">
Where my action-mapping is defined as follows:
<action path="/switchLayout" type="org.appfuse.webapp.action.SwitchLayoutAction"> <forward name="printLayout" path="/layouts/printLayout.jsp" /> <forward name="baseLayout" path="/layouts/baseLayout.jsp" /> </action>
Then in SwitchLayoutAction.java, I have the following code:
boolean print =
Boolean.valueOf(request.getParameter("print")).booleanValue();
// see if a print parameter is passed in the request
if (print) {
log.debug("switching base layout to printing...");
return mapping.findForward("printLayout");
} else {
return mapping.findForward("baseLayout");
}
Pretty slick IMO! It's easy to make the printLayout.jsp only contain some simple wrapper stuff and only do <tile:insert attribute="content"/>. Of course, in this particular example, you could just use a print stylesheet (media="print"), but that doesn't work so well on 4.x browsers (man I hate those beotches).
Posted in Java
at Sep 24 2003, 03:01:03 PM MDT
4 Comments
Search This Site
Recent Entries
- Wine Tasting in Napa Valley
- How to build a Shot-Ski
- Bus Project Update
- Farewell to the 2011-2012 Ski Season
- Cruising around the Western Caribbean
- Spring Break!
- A Spectacular Trip to Stockholm and Madrid
- Comparing Web Frameworks and HTML5 with Play Scala at Jfokus 2012
- Play Framework 2.0 with Peter Hilton at Jfokus
- Secure JSON Services with Play Scala and SecureSocial
Posted by Will Gayther on September 24, 2003 at 03:29 PM MDT #
Posted by Matt Raible on September 24, 2003 at 03:46 PM MDT #
Posted by Kunal H. Parikh on March 04, 2004 at 07:00 PM MST #
Posted by Matt Raible on March 04, 2004 at 07:18 PM MST #