dev@jsf-extensions.java.net

RE: [JSF-EXT] writing to the xjson object server-side

From: Jeff Bond <Jeff.Bond_at_cnet.com>
Date: Tue, 31 Oct 2006 17:43:24 -0500

Ed,
 
Thanks for the reply. Yes, that would do it nicely.
 
The other thing that would be nice, as far as using this XJSON object, would be to add a "postReplacements" (or whatever) to the client-side DynaFaces object. You've got replaceElement and postReplace in there, but these are both executed per every component whose markup gets replaced. I imagine a lot of client apps would want to perform a single function once on the XJSON from the server. I thought I remembered a "postInstallHook" somewhere in the avatar threads, but didn't find one in the code.
 
Thanks again.
Jeff

________________________________

From: Ed Burns [mailto:ed.burns_at_sun.com]
Sent: Tue 10/31/2006 1:02 PM
To: dev_at_jsf-extensions.dev.java.net
Subject: Re: [JSF-EXT] writing to the xjson object server-side



>>>>> On Mon, 30 Oct 2006 16:46:51 -0500, Jeff Bond <Jeff.Bond_at_cnet.com> said:

JB> Hi,
JB> Per the subject line, I'm having trouble writing to the xjson object
JB> that DynaFaces sends up to the server via the "X-JSON" header. I'm able
JB> to access it within a ValueChangeListener fine, getting the
JB> RequestHeaderMap from ExternalContext, then calling
JB> .get(AsyncResponse.XJSON_HEADER). I can then convert that String into a
JB> JSONObject and manipulate it all I want, but cannot "put it back" in the
JB> header, as the RequestHeaderMap is immutable. I tried getting the
JB> FacesContext and setting the "X-JSON" header to the JSONObject's string
JB> value, but this gets overwritten as soon as PartialTraversalViewRoot
JB> begins rendering the view:

JB> HttpServletResponse servletResponse = (HttpServletResponse)

JB> extContext.getResponse();

JB> servletResponse.setContentType("text/xml");

JB> servletResponse.setHeader("Cache-Control", "no-cache");

JB> String xjson =

JB> extContext.getRequestHeaderMap().get(AsyncResponse.XJSON_HEADER);

JB> if (null != xjson) {

JB> servletResponse.setHeader(AsyncResponse.XJSON_HEADER,

JB> xjson);

JB> }

JB> writer.startElement("partial-response", this);

JB> writer.startElement("components", this);


JB> As you can see here in bold, the xjson object is read directly from the
JB> (immutable) header map, then immediately placed into the
JB> servletResponse. So the question is, where do you have the opportunity
JB> to alter the xjson string? I'm not able to do it in a
JB> ValueChangeListener because it's fired before the Rendering phase. I
JB> haven't tried writing to it during the render or post-render phase b/c
JB> that requires messing with the actual component code (or writing a phase
JB> listener), and I'm not even 100% sure that once you've begun writing to
JB> the body of a response, you can change the headers at all.

JB> Has anyone had success changing the xjson object on the server? If so,
JB> where did you do it?

Thanks for catching this Jeff, you're right, it's currently impossible
to mutate the XJSON_HEADER so that the mutated value is returned to the
client.

How about this:

If there is a value in the request scope under the key
AsyncResponse.XJSON_HEADER, that value is assumed to be intended for the
XJSON_HEADER. If no such value exists, the value is copied directly
from the request headers.

Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_jsf-extensions.dev.java.net
For additional commands, e-mail: dev-help_at_jsf-extensions.dev.java.net