Disable decorating, but parse content for an Ajax request

View: New views
3 Messages — Rating Filter:   Alert me  

Disable decorating, but parse content for an Ajax request

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to disable decoration for an Ajax request. Adding ajax=true to the Ajax URL and excluding **ajax=true in decorators.xml does the trick.

<decorators defaultdir="/decorators">
    <excludes>
        <pattern>**ajax=true</pattern>
    </excludes>
    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

However, now I've just realized the power of a custom PageParser and rules to rewrite tags. So I'd prefer to get a non-decorated page and still parse the page. I'd imagine something like this would work:

<decorators defaultdir="/decorators">
    <decorator name="blank" page="blank.jsp">
        <pattern>**ajax=true</pattern>
    </decorator>
    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

Where blank.jsp just has <decorator:body/> and that's it. However, this doesn't work since the default decorator is still used for Ajax requests. Any ideas?

Thanks,

Matt

Re: Disable decorating, but parse content for an Ajax request

by Van Riper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Oct 8, 2008 at 3:30 PM, Matt Raible <matt@...> wrote:

> I want to disable decoration for an Ajax request. Adding ajax=true to the
> Ajax URL and excluding **ajax=true in decorators.xml does the trick.
>
> <decorators defaultdir="/decorators">
>     <excludes>
>         <pattern>**ajax=true</pattern>
>     </excludes>
>     <decorator name="default" page="default.jsp">
>         <pattern>/*</pattern>
>     </decorator>
> </decorators>
>
> However, now I've just realized the power of a custom PageParser and rules
> to rewrite tags. So I'd prefer to get a non-decorated page and still parse
> the page. I'd imagine something like this would work:
>
> <decorators defaultdir="/decorators">
>     <decorator name="blank" page="blank.jsp">
>         <pattern>**ajax=true</pattern>
>     </decorator>
>     <decorator name="default" page="default.jsp">
>         <pattern>/*</pattern>
>     </decorator>
> </decorators>
>
> Where blank.jsp just has <decorator:body/> and that's it. However, this
> doesn't work since the default decorator is still used for Ajax requests.
> Any ideas?

Hi Matt,

I don't know why that is not working for you. To be honest, I have
never completely understood how sitemesh decorator definitions handle
patterns. However, I do know that using different namespaces in the
requests has worked for me to apply different decorators. In your
situation, it would be something like this:

<decorators defaultdir="/decorators">
    <decorator name="blank" page="blank.jsp">
        <pattern>/ajax/*</pattern>
    </decorator>
    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

In Struts2, it is easy to define a "ajax" package with the "/ajax"
namespace for handling all my Ajax requests. I actually exclude my
ajax requests from decoration, but, I'm confident the snippet above
would work as long as you changed your Ajax requests to use a separate
"/ajax" namespace. There may be other good reasons why that would not
be easy to do in your situation, but, I thought it was worth
mentioning as one alternative approach.

Cheers, Van

--
| Michael "Van" Riper
| http://weblogs.java.net/blog/van_riper/
| http://www.linkedin.com/in/vanriper
----
| Silicon Valley Web JUG
| mailto:van_riper@...
| https://sv-web-jug.dev.java.net
----
| Silicon Valley Google Technology User Group
| mailto:van.gtug@...
| http://sv-gtug.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Disable decorating, but parse content for an Ajax request

by mraible :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the suggestion, but nothing seems to work. It seems that with the following example:

<decorators defaultdir="/decorators">
    <decorator name="blank" page="blank.jsp">
        <pattern>**ajax=true</pattern>
    </decorator>
    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

The 2nd one always gets processed, even if the first one matches. It's as if SiteMesh doesn't stop with the first rule. Maybe what I need is <excludes> at the decorator level?

    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
        <excludes><pattern>**ajax=true</pattern></excludes>
    </decorator>

Matt

On Thu, Oct 9, 2008 at 2:19 AM, ajg <sitemesh-users@...> wrote:
I solved the same problem by placing the equivalent of
       <pattern>*ajax=true*</pattern>
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=481818&messageID=571588#571588


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...