webtier@glassfish.java.net

Re: [webtier] JSF2: using JavaScript to update a component

From: <webtier_at_javadesktop.org>
Date: Sun, 30 Aug 2009 09:18:51 PDT

Jim,
Here's a rundown of yesterday's experiences with the Aug28 nightly build.

#1: It doesn't seem to be executing my JavaScript. My renderer writes something like this:

&lt;div id="diagram" ... &gt; ... html here ...&lt;/div&gt; &lt;script&gt; ... javascript here ... &lt;/script&gt;

I tried putting the script inside the div, but to no avail. The subtree does get replaced though, and the responseText on the client side looks good.

#2: So, try the script execution function from Hakem's blog. It immediately trips up when assigning the CDATA contents to the tmp node's innerHtml, but I deleted the offending JavaScript and got it to work. It blinks badly though when replacing the diagram.

#3: Try working around the blinking by rendering an empty div with the diagram's id on it followed by the real stuff, and then on the partial update replace the empty div and execute the JavaScript/JSON update code.

The JSON includes an array enclosed in square brackets. When the ResponseWriter encountered the left square bracket, it replaced it with a right one, closed the CDATA block and opened a new one. Because this code should in theory work in a non-JSF environment, I use the writer's write(String) method, not the higher-level methods, so I wouldn't expect it to do something like that.

After replacing the square brackets with new Array(...) it works well, still using the script execution function from the blog. I worry that the empty div hack will come back to bite me though.
[Message sent by forum member 'judys' (judy_at_apprisant.com)]

http://forums.java.net/jive/thread.jspa?messageID=362366