Hi, I've tried the example. It works +1 So we can use document.createElement("script") for [3] and [4]
regards alex 2009/5/8 Ganesh <gan...@j4fry.org> > It does work (even cross-browser). Try this: > > *<html> > <body> > <input type="submit" value="test" id="test"> > <script>//<!-- > var scriptTag = document.createElement("script"); > scriptTag.src="test.js"; > var item = document.getElementById('test'); > item.parentNode.insertBefore(scriptTag, item); > //--> > </script> > </body> > </html> > > with test.js having one line: > alert('test'); > > It's the DOM action that triggers the script execution. > > Best regards, > Ganesh > * > Alexander Bell schrieb: > >> Hi, >> >> I don't understand the solution for [3]. >> I've got for instance the following tag on my page: <script >> type="text/javascript" src="http://my.source.com/myscript.js" />. >> So we have to execute all the script code inside that file. Does this work >> with document.createElement("script")? >> Because this only create a DOM element but I'm not sure that the >> script-code is executed (especially in IE 5-6). >> >> regards alex >> >> 2009/5/8 Ganesh <gan...@j4fry.org <mailto:gan...@j4fry.org>> >> >> >> Hi, >> >> There are four kinds of script constructs I can image may becoming >> pulled in through an ajax request: >> >> [1] component does startElement("script", component) ... >> endElement("script") >> [2] XHTML markup contains <script type="text/javascript"> ... >> </script> (or component writes this directly to the stream) >> [3] markup contains <h:outputSrcipt> >> [4] markup contains <script src=...> >> >> IMHO only [1] qualifies to be included in the <eval> section of >> the AJAX response by the PartialResponseWriter. Execution on the >> Javascript side can happen with >> window.execScript(theActualScriptContent) like Matthias proposed. >> Matthias, can you explain the advantages of this? >> >> [2] should be recognized by our embedded Javascript runScripts >> function which in fact also does window.execScript. Werner, I >> think we agree on this. Everything else would cause parsing of the >> XHTML markup. >> >> For [3] Werners document.createElement("script") approach can be >> suitable though I'm not sure how you want to send this down to the >> browser. Are you planning to run on the <extension> tag in the >> ajax XMLSchema? >> >> Werner, your example for document.createElement("script") was >> based on case [4]. But how do you want to do this? Are you >> planning to parse all the markup for script tags with src >> attributes? Maybe here an extension to our embedded Javascript >> runScripts function could make sense? This could also solve [3]! >> >> Best regards, >> Ganesh >> >> Werner Punz schrieb: >> >> Yes but then I have to fetch the script via xhr... >> which means more code on the javascript side of things! >> >> >> >> Werner >> >> >> >> Matthias Wessendorf schrieb: >> >> isn't it better to do this in IE: >> window.execScript(theActualScriptContent); >> >> and in FF and other this: >> window.eval(theActualScriptContent); >> >> -Matthias >> >> ---------- Forwarded message ---------- >> From: Werner Punz <werner.p...@gmail.com >> <mailto:werner.p...@gmail.com>> >> Date: Fri, May 8, 2009 at 4:54 PM >> Subject: Re: MyFaces 2.0 PartialResponseWriter + EVALs >> To: dev@myfaces.apache.org <mailto:dev@myfaces.apache.org> >> >> >> Werner Punz schrieb: >> >> Hello everyone: >> >> I checked what has been done on the Partial Response >> Writer for the Rendering. It is very basic, so I would >> propose following enhancement. >> >> Since we need separate eval blocks for javascripts, we >> implement a PartialResponseWriterImpl which fetches >> the scripts >> from components and later allows those scripts to be >> pushed into the eval part of the partial response. >> >> There is a reason for that. >> >> Although we have embedded javascript parsing in our >> javascripts I would see that as optional feature for >> badly behaving component sets. >> >> The normal way for a component writer still is: >> a) startElement("tagName", component) >> b) writeAttribute... >> >> write >> >> c) endElement >> >> The way Trinidad and others did it was simply to check >> for scripts at startElement and push them into a >> separate eval datastructure later to be processed (in >> our case after the update part of the p >> PartialResponse a separate eval stage has to be added) >> >> I would start to work on this issue if it is ok with >> anyone... >> The entire functionality should be put into our >> PartialResponseWriterImpl not into the API, and will >> be hooked into >> >> processPartial of PartialViewContextImpl >> >> I am not sure how to deal with script src="..." on the >> protocol and javascript level. >> >> Werner >> >> >> >> >> Ok here is my idea regarding sript src=".... >> >> I would transform that on the server side to a small >> javascript ala >> var scriptTag = document.createElement("script"); >> scriptTag.src="<src>"; document.body.append(scriptTag); >> since the eval is executed after the rendering is done, >> this should be >> even safe on IE6! >> >> That also would still mean that the update CDATA block is just >> javascript only without any preprocessing which then can >> be pushed >> straight into the eval function! >> >> >> Werner >> >> >> >> >> >> >> >> >> -- >> Mit freundlichen Grüßen / Kind regards >> Alexander Bell >> >> J4Fry OpenSource Community >> Internet: http://www.j4fry.org >> E-Mail: alexander.b...@j4fry.org <mailto:alexander.b...@j4fry.org> >> Webprofil: http://www.j4fry.org/alexanderbell.shtml >> >> -- Mit freundlichen Grüßen / Kind regards Alexander Bell J4Fry OpenSource Community Internet: http://www.j4fry.org E-Mail: alexander.b...@j4fry.org Webprofil: http://www.j4fry.org/alexanderbell.shtml