You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alfie Kirkpatrick <Al...@ioko.com> on 2009/11/03 12:31:23 UTC

Same page, two different content-types

Hi, I'd like to have the same page class return two different content
types depending on circumstances. Is this possible? The existing
ContentTypeWorker modifies the component model which is immutable at
runtime.

 

In particular (and I realise this is a hack), I want to use locale to
decide between HTML and XML rendering for a page.

 

Thanks,

Alfie.


Re: Same page, two different content-types

Posted by Toby Hobson <to...@googlemail.com>.
Hi Alfie

I guess you could use a url rewrite:

public class MyAccount {
 ...
}

@ContentType("text/xml")
public class MyAccountXML extends MyAccount {

}

public static void
contributeURLRewriter(OrderedConfiguration<URLRewriterRule> configuration) {
    URLRewriterRule rule = new URLRewriterRule() {

        public Request process(Request request, URLRewriteContext context) {
            if (request.getHeader("User-Agent").indexOf("XML only browser")
> 0) {
                final String path = request.getPath();
                request = new SimpleRequestWrapper(request, path + "XML");
            }
            return request;
        }

        public RewriteRuleApplicability applicability() {
            return RewriteRuleApplicability.INBOUND;
        }

    };

    configuration.add("rule", rule);
}

Not very nice but it might work for you!

Toby

2009/11/3 Alfie Kirkpatrick <Al...@ioko.com>

> Hi, I'd like to have the same page class return two different content
> types depending on circumstances. Is this possible? The existing
> ContentTypeWorker modifies the component model which is immutable at
> runtime.
>
>
>
> In particular (and I realise this is a hack), I want to use locale to
> decide between HTML and XML rendering for a page.
>
>
>
> Thanks,
>
> Alfie.
>
>