2 Replies Latest reply on Mar 18, 2016 9:27 PM by Michael Knapp

    RF 4.5.14  - a4j:jsFunction - onbeforedomupdate and oncomplete not invoked

    Michael Knapp Newbie

      RF 4.5.14 / JSF 2.2.8 / Wildfly 8.2

       

      If have the problem that onbeforedomupdate and oncomplete on a4j:jsfunction are not invoked:

       

      test.xhtml

       

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html 
          xmlns = "http://www.w3.org/1999/xhtml"
          xmlns:a4j = "http://richfaces.org/a4j"
          xmlns:rich = "http://richfaces.org/rich"
          xmlns:h = "http://java.sun.com/jsf/html"
          xmlns:f = "http://java.sun.com/jsf/core"
      >
      <h:head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      </h:head>
      <h:body style="text-align:center;" >
          <h:form>
              <a4j:jsFunction 
                  name="testCall" 
                  data="#{test.data}" 
                  onbeforedomupdate="jQuery('#domupdate').html(data)" 
                  oncomplete="jQuery('#complete').html(data)"
                  action="#{test.test}"
              >
                  <a4j:param name="test" />
              </a4j:jsFunction> 
          </h:form>
          
          <div id="domupdate" >
          ---
          </div>
          <div id="complete" >
          ---
          </div>
          
          <script>
              testCall('hello world !');
              testCall('hello world 2 !');
          </script>
      </h:body>
      </html>
      

       

      TestBean.java

       

      package com.j4care.viewer.web.beans;
      
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.RequestScoped;
      import javax.faces.context.FacesContext;
      
      @ManagedBean(name="test")
      @RequestScoped
      public class TestBean
      {
          private String data;
      
          public synchronized void test()
          {
              final FacesContext context = FacesContext.getCurrentInstance();
              this.data = context.getExternalContext().getRequestParameterMap().get("test");
              System.out.println("test called: " + data);
          }
      
          public String getData()
          {
              System.out.println("getData called: " + data);
              return data;
          }
      
          public void setData(String data)
          {
              this.data = data;
          }
      }
      
      

       

      Server log:

       

      17:41:36,481 INFO  [stdout] (default task-101) getData called: null
      17:41:36,481 INFO  [stdout] (default task-101) getData called: null
      17:41:36,482 INFO  [stdout] (default task-101) test called: hello world !
      17:41:36,482 INFO  [stdout] (default task-101) getData called: hello world !
      17:41:36,542 INFO  [stdout] (default task-102) getData called: null
      17:41:36,542 INFO  [stdout] (default task-102) getData called: null
      17:41:36,542 INFO  [stdout] (default task-102) test called: hello world 2 !
      17:41:36,543 INFO  [stdout] (default task-102) getData called: hello world 2 !
      

       

      HTTP Reqest/Response

       

      j_idt5=j_idt5&javax.faces.ViewState=2822162167152350826%3A-3117259642620583857&javax.faces.source=j_idt5%3Aj_idt6&javax.faces.partial.execute=j_idt5%3Aj_idt6%20%40component&javax.faces.partial.render=%40component&test=hello%20world%20!&org.richfaces.ajax.component=j_idt5%3Aj_idt6&j_idt5%3Aj_idt6=j_idt5%3Aj_idt6&rfExt=null&AJAX%3AEVENTS_COUNT=1&javax.faces.partial.ajax=true

        • 1. Re: RF 4.5.14  - a4j:jsFunction - onbeforedomupdate and oncomplete not invoked
          Michael Knapp Newbie

          First HTTP Request

           

          j_idt5=j_idt5&javax.faces.ViewState=2822162167152350826%3A-3117259642620583857&javax.faces.source=j_idt5%3Aj_idt6&javax.faces.partial.execute=j_idt5%3Aj_idt6%20%40component&javax.faces.partial.render=%40component&test=hello%20world%20!&org.richfaces.ajax.component=j_idt5%3Aj_idt6&j_idt5%3Aj_idt6=j_idt5%3Aj_idt6&rfExt=null&AJAX%3AEVENTS_COUNT=1&javax.faces.partial.ajax=true
          

          Response

           

          <?xml version='1.0' encoding='UTF-8'?>
          <partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[2822162167152350826:-3117259642620583857]]></update><extension id="org.richfaces.extension"><beforedomupdate>jQuery('#domupdate').html(data);</beforedomupdate><complete>jQuery('#complete').html(data);</complete><data>"hello world !"</data></extension></changes></partial-response>
          

           

          Second HTTP Request

           

          j_idt5=j_idt5&javax.faces.ViewState=2822162167152350826%3A-3117259642620583857&javax.faces.source=j_idt5%3Aj_idt6&javax.faces.partial.execute=j_idt5%3Aj_idt6%20%40component&javax.faces.partial.render=%40component&test=hello%20world%202%20!&org.richfaces.ajax.component=j_idt5%3Aj_idt6&j_idt5%3Aj_idt6=j_idt5%3Aj_idt6&rfExt=null&AJAX%3AEVENTS_COUNT=1&javax.faces.partial.ajax=true
          

          Response

           

          <?xml version='1.0' encoding='UTF-8'?>
          <partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[2822162167152350826:-3117259642620583857]]></update><extension id="org.richfaces.extension"><beforedomupdate>jQuery('#domupdate').html(data);</beforedomupdate><complete>jQuery('#complete').html(data);</complete><data>"hello world 2 !"</data></extension></changes></partial-response>
          
          • 2. Re: RF 4.5.14  - a4j:jsFunction - onbeforedomupdate and oncomplete not invoked
            Michael Knapp Newbie

            found out myself that it has to be "event.data" in RF 4.5 instead of "data" like in RF 3.3

            because internally this finction is created:

             

            function anonymous(event) {
            try {jQuery('#complete').html(data);} catch (e) {window.RichFaces.log.error('Error in method execution: ' + e.message)}
            }
            

            this works:

             

                    <a4j:jsFunction
                        name="testCall"
                        data="#{test.data}"
                        onbeforedomupdate="jQuery('#domupdate').html(event.data)"
                        oncomplete="jQuery('#complete').html(event.data)"
                        immediate="true"
                        action="#{test.test}"
                        bypassUpdates="false"
                    >
                        <a4j:param name="test" />
                    </a4j:jsFunction>