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.