I have a generic error page which is not decorated by SiteMesh.
May I know what is the reason ?
<filter>
<display-name>SiteMesh_Filter</display-name>
<filter-name>SiteMesh_Filter</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SiteMesh_Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/pages/error.jsp</location>
</error-page>
Thanks.
This is the most recent archive of the original issue.
This is the closed issue page.
So, it looks like you need to make sure that you're not using a release that's more than 2 years old :), and you need to make sure that your SiteMesh filter is configured to process error pages by including:
<dispatcher>ERROR</dispatcher>
along with whatever else you need...
I'm going to assume you're using Sitemesh 3 as a decorator. Your configuration in the questions tells me you're using Sitemesh 2, but you mentioned using Sitemesh 3 in the comment to @kschneid answer.
Sitemesh 3 uses a Selector
implementation to select which requests it can buffer (decorate). By default this is the org.sitemesh.webapp.contentfilter.BasicSelector
. This selector has two constructors namely:
public BasicSelector(String... mimeTypesToBuffer) {
this(false, mimeTypesToBuffer);
}
public BasicSelector(boolean includeErrorPages, String... mimeTypesToBuffer) {
this.mimeTypesToBuffer = mimeTypesToBuffer;
this.includeErrorPages = includeErrorPages;
}
The former is used by the BaseSiteMeshFilterBuilder
to construct the selector by default. This means the includeErrorPages
property will be set to false
and only pages with a status of 200 OK will be buffered by the filter. To overcome this you will need to somehow use the other constructor and set includeErrorPages
to true
.
This can be done by subclassing org.sitemesh.config.ConfigurableSiteMeshFilter
and override the protected applyCustomConfiguration(SiteMeshFilterBuilder builder)
method ending up with a method similar to:
public class ErrorPageEnabledSiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder.setCustomSelector(new BasicSelector(true, "text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml"))
}
}
The above will instruct the builder to use the custom selector which now will decorate error pages. The only thing left is to add a instance of ErrorPageEnabledSiteMeshFilter
to your ServletContext
replacing the old one.