Re: Different decorator for different paths

Frederic Burlet <[email protected]> Wed, 13 Dec 2006 05:58:27 CST
Newsgroups gmane.comp.web.sitemesh.general
Message-ID <4980091.1166011138941.JavaMail.os-j2ee@opensymphony01.managed.contegix.com>
I had the same issue til today and I didn't change anything in the code.
I'm using sitemesh 2.3 with webwork 2.2.4 in tomcat 5.5.7.
My config is the following one:

<decorators>
    <decorator name="classic" page="/WEB-INF/jsp/decorators/main.jsp">
        <pattern>/*</pattern>
    </decorator>
    <decorator name="popup" page="/WEB-INF/jsp/decorators/popup.jsp">
        <pattern>/*.popup.action</pattern>
    </decorator>
</decorators>

If I have an url of type: http://hostname/path/to/something.popup.action?param=p1&param=p2 I'm expecting the popup decorator to be applied (but it's not always the case - fortunatly, today it was).

I dug into the code with a debbuger. As Jeff stated a few days ago, there is a call to
public Decorator getDecorator(HttpServletRequest request, Page page) in ConfigDecoratorMapper. If you go deeper, you'll see a call to configLoader.getMappedName(thisPath). thisPath being the url path. This delegates the job to pathMapper.get(path)... and there we are. The pathMapper is a wrapper around an HashMap containing mappings between patterns and keys.

First we try to get the exact key, but as there are no pattern with exact match, we try to find complex key. This method is looping over the keySet() of the HashMap, the order in which elements are iterated is not guaranteed. Sometimes, first element is /*, sometimes, it's /*.popup.action. This could explain the reason why it does'nt work... or sometimes it does.

In my example, if /* is the first matched pattern (it will match for all url pattern), the classic decorator will be applied. If /*.popup.action is the first matched pattern, the "popup" decorator will be applied only for url path ending by popup.action and "classic" decorator will be applied to any other url...

Does it make sense ?

Hope this helps.

Fred.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=48405&messageID=107206#107206

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]