1

Given a simple template JSP for rendering by Sitemesh 3:

<%@include file="../jsp_inc/taglibs.jsp" %>
<!DOCTYPE html>
<head>
    <link rel="stylesheet" type="text/css" href='<c:url value="/css/global.css" />' >
</head>
<body>
<h1>[HEADING]</h1>
<div>
    <sitemesh:write property='body'/>
</div>
</body>

That template works as expected, inserting the content of the JSP element into the template.

As you might expect from the above, I want to be able to insert a value set in the JSP (eg. h1 element) into the appropriate element in my template.

I tried:

<sitemesh:getProperty property="page.heading"></sitemesh:getProperty>

in the template/decorator and:

<content tag="heading"></content>

In the JSP, per another question on SO but I think that may have been referring to Sitemesh 2. I am using Sitemesh 3.

Any suggestions?

DaFoot
  • 1,475
  • 8
  • 29
  • 58
  • 1
    Incidentally this post changed my life http://stackoverflow.com/questions/1296235/jsp-tricks-to-make-templating-easier I see no reason to ever use SiteMesh again, jsp tags are thoroughly better – Magnus Dec 22 '16 at 15:55

1 Answers1

11

Not sure if you're still using Sitemesh 3, but I was checking it out and after trolling through the source code found that you have configure the builder.

I'm using the Java based configuration and created my own subclass that adds a tag processing rule bundle that supports Sitemesh 2 style content blocks:

public class MySiteMeshFilter extends ConfigurableSiteMeshFilter {
    @Override
    protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
        builder.addTagRuleBundle(new Sm2TagRuleBundle());
    }
}

Via XML configuration in sitemesh3.xml:

<sitemesh>
    <content-processor>
        <tag-rule-bundle class="org.sitemesh.content.tagrules.html.Sm2TagRuleBundle" />
    </content-processor>
    <!-- Your mappings go here -->
    <mapping ... />
</sitemesh>

Doing this allows you to use content tags like:

<content tag="heading"></content>

In the decorator/template page use a sitemesh:write tag instead of sitemesh:getProperty which doesn't exist anymore:

<sitemesh:write property="page.heading"/>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Phuong LeCong
  • 1,834
  • 16
  • 19
  • Thanks @Phuong LeCong. This worked for me. I wonder why this answer is not up-voted/accepted. – hemu Oct 31 '14 at 12:14