Dashboard > WebWork > ... > FAQ > Problem getting SiteMesh to work with web.xml errorPage
  WebWork Log In View a printable version of the current page.  
  Problem getting SiteMesh to work with web.xml errorPage
Added by tm_jee, last edited by tm_jee on Dec 03, 2006
Labels: 
(None)

The doFilter() method of PageFilter sets the boolean variable FILTER_APPLIED on the request to true, before executing. When an exception occurs in the call to chain.doFilter(), the execution stops. After the servlet invokes the error page, the PageFilter is invoked again, but stops when it sees that the FILTER_APPLIED attribute is already set to true.

The solution is to extend the PageFilter, catch all exceptions and set the FILTER_APPLIED variable to null. Then use this filter in the web.xml.

public class ErrorHandlingSiteMeshPageFilter extends PageFilter {
 
    public void doFilter(ServletRequest request, ServletResponse rs, FilterChain chain) throws IOException, ServletException {
        try {
            super.doFilter(request, rs, chain);
        } catch (RuntimeException e) {
            clearFilteredVariable(request);
            throw e;
        } catch(IOException e) {
            clearFilteredVariable(request);
            throw e;
        } catch(ServletException e) {
            clearFilteredVariable(request);
            throw e;
        }            
    }
    
    private void clearFilteredVariable(ServletRequest request) {
        request.setAttribute(FILTER_APPLIED, null);
    }
}

For more information of related discussion, see here

Sollution contributed by Hendrikd. Thx Hendrikd.

This will be included as part of Sitemesh 2.4:

http://jira.opensymphony.com/browse/SIM-168

Cheers,
Scott

Posted by Scott Farquhar at Jan 08, 2007 00:14 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators