1 Reply Latest reply on Apr 25, 2012 12:55 PM by healeyb

    a4j:jsFunction sending a synchronous AJAX request and returning a value

    awinizki

      I want to construct an a4j:jsFunction that:

      • sends a synchronous (!) AJAX request
      • waits until a response has arrived
      • returns a value to the caller depending on data sent back from the server

      Does anybody know how to do this?

        • 1. Re: a4j:jsFunction sending a synchronous AJAX request and returning a value
          healeyb

          Hi, this example passes data to and back from the server. You need to use action= rather than actionListener

          or the a4j:param isn't picked up (unless they've fixed it).

           

          <h:commandButton value="click me" onclick="jsTest();"/>

           

          <a4j:jsFunction name="jsTest"

                                 oncomplete="alert(event.data)"

                                 action="#{bean.jsTestAction}"

                                 data="#{bean.jsTestData}">

                  <a4j:param name="p1" value="Fred" assignTo="#{bean.jsTestParam}"/>

          </a4j:jsFunction>

           

          public class Bean ... {

               private String jsTestData;

               private String jsTestParam;

           

              public String jsTestAction() {

                  jsTestData = "Hello " + jsTestParam;

                  return null;

              }

               // getters & setters removed

          }

           

          The alert displays "Hello Fred".

           

          Regards,

          Brendan.