Skip to main content

Passing arbitrary data between JSP pages and SiteMesh decorators

Posted by zarar on January 19, 2006 at 10:49 AM PST

I try not to complain about lack of documentation. So in this blog entry, I'll show how simple it is to pass in arbitrary data from JSP pages to SiteMesh decorators.

For every piece of information that you want to pass from the JSP page to the SiteMesh decorator, create a <content> tag. In the following example, I want to pass in two pieces of data, a "page name" and a "site section". So I must declare two content tags in the JSP page:

<content tag="pageName">
    Login Page
</content>
<content tag="siteSection">
    Administration
</content>

Now, all thats left is telling the SiteMesh decorator to access this information, and that is very easily done using the following syntax in the decorator:

<decorator:getProperty property="page.pageName"/>
<decorator:getProperty property="page.siteSection"/>

That's it. Now you can pass in anything you want and aren't restricted to using <decorator:head/>, <decorator:body/> and <decorator:title/>. My problem with these three tags is that I don't want to declare a head, title and body tag for every JSP page since the JSP page is usually the "main" content of the page and shouldn't have to declare such basic HTML elements. IMHO using tags is a cleaner and more powerful solution as you can pass in an unlimited amount of data without using specific tags. However, combining the three tags mentioned with the <content> tag is also a fine strategy.

Related Topics >>