5 Replies Latest reply on Dec 26, 2014 3:40 AM by smilefeng

    Problem with a4j:jsFunction data in Richfaces 4

    schoenb

      Hi,

       

      I have defined a function like this im my JSF2 Project

       

      <a4j:jsFunction ajaxSingle="true" data="#{sBOsmShow.longitude}" name="centerAndZoom" oncomplete="alert(data)">

      </a4j:jsFunction>

       

      I trigger this function from a a4j:commandButton

       

      <a4j:commandButton value="Anzeigen" onclick="centerAndZoom();" execute="zoomDataGrid"/>

       

      After clicking the button no alert-box is displayed. The getLogitude is called in the session bean. If I change alert(data) to alert('test') the "test" is displayed. It seems there is a problem using data from the sessionbean as parameter fpr the javascript function.

       

      Richfaces 4.3.2

      JBoss 7.1.1

       

      Can some help me?

       

      Greetings

       

      Arndt

        • 1. Re: Problem with a4j:jsFunction data in Richfaces 4
          schoenb

          Is use Richfaces 4.2.3 - a typo

          • 2. Re: Problem with a4j:jsFunction data in Richfaces 4
            healeyb

            Here's an example that I have used in the past, there are a few minor changes from your code above, notably the use

            of a4j:param and event.data. Hopefully you can adapt this to meet your requirements.

             

            <a4j:commandButton 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 String jsTestAction() {

                    jsTestData = "Hello " + jsTestParam;

                    return null;

            }

             

            Regards,

            Brendan.

            1 of 1 people found this helpful
            • 3. Re: Problem with a4j:jsFunction data in Richfaces 4

              Your mistake in receive data via "data" variable, you must take data via "event.data"

               

              This is examle from book:

               

              <h:form>

                   <input type="button" value="Update" onclick="updateName('Joe');"/>

                  

                   <a4j:jsFunction name="updateName" render="showname" data="#{jsFunctionNameBean.greeting}" oncomplete="alert(event.data)">

                        <a4j:param name="param1" assignTo="#{jsFunctionNameBean.name}"/>

                   </a4j:jsFunction>

               

                   <h:outputText id="showname" value="#{jsFunctionNameBean.greeting}"/>

              </h:form>

               

              @ManagedBean (name="jsFunctionNameBean")

              @RequestScoped

              public class JSFunctionNameBean {

                   private String name; // setter and getter

                  

                   public String getGreeting () {

                        return "Hello "+this.name;

                   }

              }

               

              Regards,

              Adam.

              • 4. Re: Problem with a4j:jsFunction data in Richfaces 4
                schoenb

                Thank you very much. I my overlooked this in the docs.

                • 5. Re: Problem with a4j:jsFunction data in Richfaces 4
                  smilefeng

                  thank you very much for your answer