SiteMesh 2

How to integrate Sitemesh into web application:

Add sitemesh into web app:

  • 1) Add sitemesh dependency

a) drop sitemesh.jar into WEB-INF\lib
OR
b) use maven

<dependency>
    <groupId>opensymphony</groupId>
    <artifactId>sitemesh</artifactId>
    <version>2.4.2</version>
</dependency>
  • 2) Add Filter to web.xml
<!-- SiteMesh -->
<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
  • 3) Create decorators.xml file
    <?xml version="1.0" encoding="UTF-8"?> 
    <decorators defaultdir="/decorators"> 
        <decorator name="basic-theme" page="basic-theme.jsp"> 
            <pattern>/*</pattern> 
        </decorator> 
    </decorators>
  • 4) Use Sitemesh tag libs inside the theme jsp files:
    <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
    <decorator:body />

Notes:

  • sitemesh-defaul.xml expects decorators to be at : /WEB-INF/decorators.xml
  • Theme locations are specified in decorators.xml : <decorators defaultdir="/decorators">
  • File structure:

(source)

Reference:

Advertisements
Posted in Java, Web

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: