DH-14:

Yes, I ended up using a block.

For those like me that don't know what a block is, it's an XML-tagged
section of your template, demarcated via <block
id="yourIdentifierHere"></block> tags. The block can be injected into page
or component code using the @Inject annotation as an object of type Block,
with a variable name in the form of _yourIdentifierHere. The variable name
must match the ID used in the <block> tag - except for the leading
underscore, which is stripped by Tapestry. 

This Block object can be returned from the event handler, and is rendered
prior to being sent back, in JSON form, as the reply to the AJAX request. 

Surely some of you will ask "Why was that not obvious at the outset,
Renger?". I can only say that it took me some several re-readings of the
documentation to identify the Block method as a potential solution, and a
few more to figure out how it worked. There is, to my knowledge, no section
of the documentation that sets out what Blocks are, how they work, and what
use-cases they pertain to, with the exception of this excerpt from the AJAX
section of the Tapestry reference:

For an Ajax request, the return value from an event handler method is
processed differently than for a traditional action request. In an normal
request, the return value is the normally name of a page (to redirect to),
or the Class of a page to redirect to, or an instance of a page to redirect
to.

For an Ajax request, a redirect is not sent: any response is rendered as
part of the same request and sent back immediately.

The possible return values are:

    * A Block or Component to render as the response. The response will be a
JSON hash, with a "content" key whose value is the rendered markup. This is
the basis for updates with the Zone component.
    * A JSONObject or JSONArray, which will be sent as the response.
    * A StreamResponse, which will be sent as the response. 

I say that merely to justify the bandwidth I took up to ask my question. I
remain very appreciative of HLS' work, and I thank the responders for their
attention.

-- 
View this message in context: 
http://www.nabble.com/How-to-render-a-page-as-JSON-formatted-AJAX-response--tp24081692p24091906.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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

Reply via email to