1 Reply Latest reply on Apr 27, 2008 10:49 PM by Sergey O

    JavaScript in AJAX responses: does not get executed

    Sergey O Newbie

      I have custom JSF component that I am trying to adapt for use under AJAX4JSF/RichFaces.
      The component is a wrapper around ActiveX control fed with data through
      The original plain JSF version of the component emits HTML OBJECT tag and also
      JavaScript code to activate the object and initialize it with data to display.
      I am trying to modify the control so that whenever data update is done inside
      AJAX request, only a delta of the data is sent back instead of the whole data
      Another important piece is to avoid reinstantiating the ActiveX control so
      as to avoid a flicker.
      Thus what I want to do is roughly:

      AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
      if (! ajaxContext.isAjaxRequest())
      // full repaint
      ... emit HTML tag for ActiveX object ...
      ... emit JavaScript code to load the control with initial data ...
      // delta update
      ... emit JavaScript for partial update of data inside ActiveX control ...

      The first part (non-AJAX request) works fine. ActiveX control gets
      instantiates and loaded with initial data.The second part does not work. It appears that JavaScript code emited in
      response to AJAX request does not get executed at all inside the browser.I can verify with HTTPWatch that the browser does indeed receive a response
      from the server that includes valid JavaScript code, however this code does not
      get executed.As a matter of fact, even simple script containing alert() statement I tried
      to send back does not get executed.Something like this:

      {script type="text/javascript"}//<![CDATA[
      alert('About to execute DELTA update!');

      (NB: I replaced tag brackets with {} for purposes of posting to this board.)

      does not display an alert.
      Is AJAX4JSF supposed to handle and execute JavaScript code sent back by the
      server in response to AJAX request?If yes, why it may fail to work in this particular case?I am using the latest stable build of RichFaces.Thanks,

        • 1. Re: JavaScript in AJAX responses: does not get executed
          Sergey O Newbie

          While we are at it...

          I started looking into AjaxScript.js and from what I can see it appears that AJAX updates work by replacing (in updatePagePart) the whole inner-HTML code for the JSF component.

          Is there any way I can have only some parts of JSF component updated in the browser by AJAX response, while other parts left alone?

          Specifically, if HTML code for the component includes ActiveX control, I certainly do *not* want it to be reinstantiated as it is an extremely costly operation leading to a flicker and then lots of repainting during control initialization.