tags:

views:

71

answers:

2

Hi All,

I've been looking but can't find the the documentation:

Is there a way to have a page render a response without the wrapping HTML elements and just print whatever is provided in the body of the tml or alternatively whatever is set in MarkupWriter.write during @BeginRender?

I need a page that does some server side processing and returns pure javascript for an external application to request.

If that is impossible, is it possible to expose the tapestry Ioc to a servlet in the same app?

Thanks, p.

+2  A: 

One possibility is to use MarkupWriter.writeRaw instead of MarkupWriter.write in @BeginRender. Here is a link to the API documentation.

Edit: If you don't want the document to contain anything else except your text content here is one way to achieve this.

@Inject
private Response response

void onActivate() throws IOException {
    PrintWriter writer = response.getPrintWriter("text/html");
    writer.append("foobar");
    writer.close();
}
ponzao
.. but the .tml would still be rendered, meaning html would still print to the response .. right? from what i can tell, i must have a tml and it must have an <html> element
pstanton
Aah okay so let's say you have some code like <script>alert("foo");</script> and you want to so it as such, not wrapped inside <html><head>... Then you could always inject the response and in onActivate get an OutputStream or a PrintWriter and write the response manually, I will add an example.
ponzao
thanks that's perfect. FYI you still need to have a .tml file otherwise tapestry throws an exception (internally).
pstanton
Glad to help. Okay good to know, I didn't test my solution really extensively :)
ponzao
+2  A: 

Sorry ponzao, but i found a better solution courtesy of Thiago on the tapestry mail list:

public class MyPage
{
    StreamResponse onActivate()
    {
        return new TextStreamResponse("text/plain", "some text");
    }
}

this way you don't need to revert to the servlet API and don't need a tml.

adapted from this eg: http://wiki.apache.org/tapestry/Tapestry5HowToCreateADynamicPDF

pstanton
Okay that seems more Tapestryesque.
ponzao
Btw select it as the correct answer so this question doesn't remain answerless ;)
ponzao
thx, had to wait a day (so rules).
pstanton

related questions