dev@jsf-extensions.java.net

writing to the xjson object server-side

From: Jeff Bond <Jeff.Bond_at_cnet.com>
Date: Fri, 27 Oct 2006 13:56:15 -0400

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

extContext.getResponse();

servletResponse.setContentType("text/xml");

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

String xjson =

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

if (null != xjson) {

servletResponse.setHeader(AsyncResponse.XJSON_HEADER,

xjson);

}

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

writer.startElement("components", this);

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