Tuesday, October 23, 2007

GWT & SiteMesh… Friends or foes?

SiteMesh is a powerful lay outing framework for Java web applications based on the “Decoration Pattern”.
It is the lay outing framework that fuels AppFuse project and the new bad boy in Java web development jammed market “Grails”.
If you are anything like me, then you are thinking of Google Web Toolkit (GWT) every day.
GWT & SiteMesh are very powerful technologies but do they mix smoothly without collateral damage?
That’s what I have been trying to achieve in a small Java web application.
My web application has the following structure:

/context-root/
|
-------- shopping
|
------ Cart

Shopping folder contains my GWT module host page (Cart.html) and cart folder contains com.web.gwt.cart.ManageCart.html
Here is Cart.html head tag:

<head>
<meta tag name="gwt:module" content="/armada/shopping/Cart=com.web.gwt.cart.ManageCart">
</head>

Now, with every thing is neat and dandy, lets try to request our spoiled GWT Cart.html page.
Do you see any thing?
No!
SiteMesh template is shown but the Cart.html is not.
Here FireFox’s plug-in “FireBug” comes to rescue.
FireBug shows that the HTTP response contains my SiteMesh template twice!
Damn, I forgot that SiteMesh allows us to exclude resources based on URL patterns.
Here is my first shot:
(decorator.xml file):

<excludes>
<pattern>/shopping/Cart/*.html</pattern>
</excludes>

Let’s try to see our spoiled GWT Cart.html page again.

Nothing again!
I started to lose my nerves but let me see FireBug again.
FireBug shows that the actual request for Cart.html page contains some extra parameters in the form of:
Cart.html?32451237845234
Here is my second shot for decorators.xml:

<excludes>
<pattern>/shopping/Cart/*.html?*</pattern>
</excludes>

This time, Cart.html is destined to work, right?
Right!
So, what is the moral? GWT & SiteMesh are friends and good amigos indeed.