1 Reply Latest reply on Dec 6, 2007 2:08 PM by Jose de Castro

    Scope change in oncompete handler for a4j:commandButton?

    Jose de Castro Newbie

      Did the scope in which the oncompete handler is executed change in 3.1?

      The behavior for the following component declaration changed in RichFaces 3.1 but I can't figure out why. I have been using this (validate, disabled, call, enable) pattern in 3.0.1 for while and would like to move to 3.1 to make use of Seam 2.0.

      Expected result:

      * User clicks on 'Open' button
      * Form is validated
      * Locally-scoped cmdRef variable is used to hold a reference to button
      * projectManager.open is called
      * Button is re-enabled
      * Client-side open hander is invoked

      <a4j:commandButton id="cmdOpen" value="Open"
       onclick="if(projectGrid.validate()){var cmdRef=this; this.disabled=true;}else{return false;}"
       actionListener="#{projectManager.open}"
       oncomplete="cmdRef.disabled=false; dialog.handleOpen('SAVE');"
      />


      As I said, this was working fine in 3.0.1. However, once I upgraded to 3.1, processing of oncomplete seems to stop when it reaches cmdRef.disabled. I have confirmed that oncomplete is being called by adding an alert before it. I can also switch the order of my statements and have handleOpen called but the button is never re-enabled.

      Any help would be greatly appreciated. I don't mind changing my approach if mine is no longer possible in the new model.

      Thank in advance,

      Jose de Castro
      Sr. Software Engineer
      Voxeo Corporation

        • 1. Re: Scope change in oncompete handler for a4j:commandButton?
          Jose de Castro Newbie

          Well, I found my answer. It turns out that 3.1 did indeed change the way it executes oncomplete handlers. It is doing window.eval instead of executing the reference to options.oncomplete passed in to A4J.AJAX.Submit.

          Can someone on the ajax4jsf team tell me why the change was made and if there's a way to suppress "org.ajax4jsf.oncomplete" from the request?

          Old way:

          A4J.AJAX.finishRequest = function (req) {
           var options = req.options;
           A4J.AJAX.status(req.containerId, options.status, false);
           if (options.oncomplete) {
           LOG.debug("Call request oncomplete function after processing updates");
           window.setTimeout(function () {
           options.oncomplete(req, req.domEvt, req.getJSON("_ajax:data"));
           }, 50);
           }
           if (options.eventsQueue) {
           var eventsQueue = A4J.AJAX._eventsQueues[options.eventsQueue];
           if (eventsQueue) {
           A4J.AJAX._eventsQueues[options.eventsQueue] = false;
           if (eventsQueue.wait) {
           LOG.debug("Queue not empty, execute next request in queue " + options.eventsQueue);
           A4J.AJAX.SubmiteventsQueue(eventsQueue);
           }
           }
           }
          };


          New way:

          A4J.AJAX.finishRequest = function (request) {
           var options = request.options;
           if ((typeof Event != "undefined") && (typeof Event.unloadElementsCache == "function")) {
           Event.unloadElementsCache();
           }
           var oncomplete = request.getElementById("org.ajax4jsf.oncomplete");
           if (oncomplete) {
           LOG.debug("Call request oncomplete function after processing updates");
           window.setTimeout(function () {
           var event = request.domEvt;
           var data = request.getJSON("_ajax:data");
           try {
           var newscript = Sarissa.getText(oncomplete, true);
           window.eval(newscript);
           }
           catch (e) {
           LOG.error("Error evaluate oncomplete function " + e.Message);
           }
           A4J.AJAX.status(request.containerId, options.status, false);
           }, 10);
           } else {
           if (options.oncomplete) {
           LOG.debug("Call component oncomplete function after processing updates");
           window.setTimeout(function () {
           options.oncomplete(request, request.domEvt, request.getJSON("_ajax:data"));
           A4J.AJAX.status(request.containerId, options.status, false);
           }, 10);
           } else {
           A4J.AJAX.status(request.containerId, options.status, false);
           }
           }