3 Replies Latest reply on Jun 2, 2009 6:26 AM by ilya_shaikovsky

    RichFaces extract out component's javascript upon rerender

    ariefzj

      Hi,

      I have a component that uses javascript to initialize it. Similar to rich:calendar concept. So, the code in the renderer will produce something like this:

      <table id="componentId">
      ..
      ..
       <script type="text/javascript">some js constructor call</script>
      </table>
      


      On first load, the component renderer generate the html code exactly as what i want. However, after rerender... when i checked through Fiddler, i can see that the script was extracted out and placed outside the component element like this:

      <script type="text/javascript">some js constructor call</script>
      <table id="componentId">
      ..
      ..
      </table>
      


      It become problem if i ask RichFaces to rerender the component only (by sending in the componentId). This is because A4J only searches "script" element only within the rerendered component id, based on the following code:

       evalScripts : function(node, isLast){
       var newscripts = this.getElementsByTagName("script",node);
       LOG.debug("Scripts in updated part count : " + newscripts.length);
       if( newscripts.length > 0 ){
      


      Since the script is outside the component block, it will not be discovered by A4J, thus preventing it from being evaluated. Thus, the newly rerendered component will not work without the javascript initialization.

      Is my theory correct?
      The workaround that we use for now is to rerender the container (parent). With that, it able to evaluate the script. But if the container has too many component, then we might experience slight delay.

      Is there a reason for this behavior? If yes, then we might have to stick with the workaround for now.

      Rich-calendar is smart, even though i specified the calendar id in the reRender attribute, all related element of the calendar will be reRendered as well including the scripts. Do you guys mind sharing any pointer on how to do this for our custom component? :)

      Thanks in advance

      p/s: our environment:-
      RF-3.3.1-GA
      JSF-RI-1.2.11
      JBoss-4.3.0