4 Replies Latest reply on Jul 20, 2007 1:04 PM by alexsmirnov

    custom AJAX request does not work

    franklu

      hi ,

      I have a problem here, wonder if someone here can help me:


      basically, I got some AJAX-enabled custom components on my jsp page (along with couple of a4j enabled tags). if i trigger an AJAX request from any of my custom components immediately after one a4j:support request been triggered( event=onblur), I will get a javascript error saying "Unknown run time error".

      after debugging i realized my AJAX request was never sent to the server.

      here are my code for sending the AJAX request:

      function lookup(actionName) {
       var formaction = window.document.forms[formName].action;
       var formName = window.document.forms[formName].id;
      
       var formdata = formName + "=" + formName + "&" + "ajaxreq=true";
      
      
       params += "&" + actionName + "=action&REQUEST_ALLODETAIL=REQUEST_ALLODETAIL;";
      
       if (window.XMLHttpRequest) {
       xmlreq = new XMLHttpRequest();
       } else if (window.ActiveXObject) {
       xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlreq.open("POST", formaction, true);
       xmlreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" );
       xmlreq.onreadystatechange = processXMLResponse;
       xmlreq.send(params);
      }
      
      function processXMLResponse() {
       if (xmlreq.readyState == 4) {
       if (xmlreq.status == 200) {
       renderTable();
       }
       }
      }
      


      and here is my code using a4j:


      <h:inputText size="17" id="AsPrncplBrkr"
       binding="#{instructionBean..principalUser}">
       <a4j:support event="onblur"
       action="#{instructionBean.processPrincipalAction}"
       reRender="wizard"/>
      </h:inputText>
      
      


      many thanks!

        • 1. Re: custom AJAX request does not work
          franklu

          additional information:

          the a4j tags are inside a a4j:region,
          and the code that triggers my custom AJAX request is outside of that region.

          
           <a4j:region renderRegionOnly="true">
           <a4j:outputPanel ajaxRendered="true">
           <h:inputText size="17" id="AsPrncplBrkr"
           binding="#{instructionBean..principalUser}">
           <a4j:support event="onblur"
           action="#{instructionBean.processPrincipalAction}"
           reRender="wizard"/>
           </h:inputText>
           </a4j:outputPanel>
          </a4j:region>
          
          <!-- AJAX - enabled - custom component -->
          <custom:allocation id="allo" binding="#{instructionBean.form.allocation}"/>
          


          thanks!


          • 2. Re: custom AJAX request does not work

            The region limit the processing of the component tree (i.e. Decode, Validation and Update Model phases). The Restore View works as usual. As soon as you have binding, it will be triggered in order to restore the tree.

            P.S. what is the reason to have a4j:outputPanel ajaxRendered="true" around input? Looks like it does not make sense.
            P.P.S. I hope you understand that wizard will not be re-rendered because of the renderRegionOnly="true"

            • 3. Re: custom AJAX request does not work
              franklu

               

              "SergeySmirnov" wrote:
              The region limit the processing of the component tree (i.e. Decode, Validation and Update Model phases). The Restore View works as usual. As soon as you have binding, it will be triggered in order to restore the tree.

              P.S. what is the reason to have a4j:outputPanel ajaxRendered="true" around input? Looks like it does not make sense.
              P.P.S. I hope you understand that wizard will not be re-rendered because of the renderRegionOnly="true"


              thanks for you quick response.

              I didn't want to confuse people so i didnt post all my jsp codes inside the a4j:region (obviously, i got some other tag named "wizrd") .

              what bothers me is my on AJAX request never hit the server (but it will work if I dont have any other pending a4j requests). any Ideas?

              • 4. Re: custom AJAX request does not work
                alexsmirnov

                 

                I will get a javascript error saying "Unknown run time error".

                I'm love Internet Explorer ! :-)
                Can you run your component in the different browser ( Firefox ), with more informative error messages ?
                I have only one thing - some time ago i has founded problem with window.forms collection, not properly updated after replace "form" node in the DOM tree.
                Can you change javascript code to use GetElementById instead of the "forms" collection ?