Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2012 12:46
Show Gist options
  • Save anonymous/4352582 to your computer and use it in GitHub Desktop.
Save anonymous/4352582 to your computer and use it in GitHub Desktop.
SiteMesh3 configuation example, showing custom decorator selector based on HttpSession.
public class MyCustomDecoratorSelector extends DecoratorSelector<WebAppContext> {
@Override
public String[] selectDecoratorPaths(Content content, WebAppContext context) throws IOException {
HttpServletRequest request = context.getRequest();
if (request.getSession().getValue("is_admin") != null) {
return new String[] {"/decorators/admin-decorator.html"};
} else {
return new String[] {"/decorators/normal-decorator.html"};
}
}
}
public class MyCustomSiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setCustomDecoratorSelector(new MyCustomDecoratorSelector());
}
}
<web-app>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.blah.MyCustomSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment