You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lars Kühne <la...@googlemail.com> on 2007/11/28 15:33:45 UTC

T5: Controlling the content type in a page render request

Hi,

I'm trying to use a tml template to serve an XML file that has dynamic
content (in fact, a Java Web Start JNLP file):

<?xml version="1.0" encoding="utf-8"?>
<jnlp xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
  spec="1.5+"
...
</jnlp>

The content itself is rendered correctly, but I'm having problems
setting the correct content type for the response.

What I tried is this:

    @Inject
    private RequestGlobals requestGlobals;

    public void onActivate(String context) {
        // ... initialize internal state from context
        HttpServletResponse response = requestGlobals.getHTTPServletResponse();
        response.setContentType("application/x-java-jnlp-file");
    }

The response still comes out as text/html.

How can I convince Tapestry that the content type should be
application/x-java-jnlp-file?

Lars

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


Re: T5: Controlling the content type in a page render request

Posted by Lars Kühne <la...@googlemail.com>.
On Nov 28, 2007 7:46 PM, Josh Canfield wrote:
> You can use: @Meta("tapestry.response-content-type=text/xml") on your page
> class.

Thanks, that seems to work for me.

> Although XML is not fully supported by tapestry at the moment. You may run
> into problems with invalid xml being generated if one of your elements
> matches an HTML element such as link or img which will render the opening
> tag, but will not close it. Also, I believe namespaces are stripped...

Thanks for the heads up, I'm now watching the tracking issue (TAPESTRY-1600).

Lars

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


Re: T5: Controlling the content type in a page render request

Posted by Josh Canfield <jo...@thedailytube.com>.
You can use: @Meta("tapestry.response-content-type=text/xml") on your page
class.
Although XML is not fully supported by tapestry at the moment. You may run
into problems with invalid xml being generated if one of your elements
matches an HTML element such as link or img which will render the opening
tag, but will not close it. Also, I believe namespaces are stripped...

Josh
On Nov 28, 2007 6:33 AM, Lars Kühne <la...@googlemail.com> wrote:

> Hi,
>
> I'm trying to use a tml template to serve an XML file that has dynamic
> content (in fact, a Java Web Start JNLP file):
>
> <?xml version="1.0" encoding="utf-8"?>
> <jnlp xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
>  spec="1.5+"
> ...
> </jnlp>
>
> The content itself is rendered correctly, but I'm having problems
> setting the correct content type for the response.
>
> What I tried is this:
>
>    @Inject
>    private RequestGlobals requestGlobals;
>
>    public void onActivate(String context) {
>        // ... initialize internal state from context
>        HttpServletResponse response =
> requestGlobals.getHTTPServletResponse();
>        response.setContentType("application/x-java-jnlp-file");
>    }
>
> The response still comes out as text/html.
>
> How can I convince Tapestry that the content type should be
> application/x-java-jnlp-file?
>
> Lars
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: T5: Controlling the content type in a page render request

Posted by Lars Kühne <la...@googlemail.com>.
On Nov 28, 2007 3:50 PM, Kristian Marinkovic wrote:
> hi lars,
>
> return an instance of StreamResponse:
>
> StreamResponse onActivate(String context) {
>         return new StreamResponse() {
>                 // implement interface
>                  public String getContentType() {
>                         return"application/x-java-jnlp-file";
>                 }
>         }
> }

Thanks, I was only aware of the StreamResponse magic for action
requests, didn't know that it's supported for page render requests as
well.

So I could do this

        StringBuilder buf = new StringBuilder();
        buf.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        // ...
        return new TextStreamResponse("application/x-java-jnlp-file",
buf.toString());

but I don't see a way to leverage tapestry's templating engine so the
xml becomes more maintainable.

I'll probably use the Meta annotation approach and fall back to
StreamResponse if I should hit one of the XML support problems Josh
mentioned.

Again, thanks to both of you,
Lars

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


RE: T5: Controlling the content type in a page render request

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi lars,

return an instance of StreamResponse:

StreamResponse onActivate(String context) {
        return new StreamResponse() {
                // implement interface
                 public String getContentType() {
                        return"application/x-java-jnlp-file";
                }
        }
}

g,
kris



"Lars Kühne" <la...@googlemail.com> 
28.11.2007 15:33
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
T5: Controlling the content type in a page render request







Hi,

I'm trying to use a tml template to serve an XML file that has dynamic
content (in fact, a Java Web Start JNLP file):

<?xml version="1.0" encoding="utf-8"?>
<jnlp xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
  spec="1.5+"
...
</jnlp>

The content itself is rendered correctly, but I'm having problems
setting the correct content type for the response.

What I tried is this:

    @Inject
    private RequestGlobals requestGlobals;

    public void onActivate(String context) {
        // ... initialize internal state from context
        HttpServletResponse response = 
requestGlobals.getHTTPServletResponse();
        response.setContentType("application/x-java-jnlp-file");
    }

The response still comes out as text/html.

How can I convince Tapestry that the content type should be
application/x-java-jnlp-file?

Lars

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