0 Replies Latest reply on Apr 3, 2011 4:13 AM by antibrumm.mfrey0.bluewin.ch

    conversationPropagation still an issue with a4j:commandbutton ? Please confirm

    antibrumm.mfrey0.bluewin.ch

      Hello all
      I've been struggling for a while now with getting the a4j commandbutton working in an ajax reRendered form. Surely first i guessed that this has something to do with richfaces and an invalid bean state as this issue was mentioned alot in other topics.


      I'm using conversations and because of that i was kinda sure that the invalid bean state issue can be ruled out.


      So finally i found a JIRA entry which states that in Seam 2.0 there was a bug in the conversation propagation which kills the a4j commandbutton. And this JIRA entry is marked as Fixed.


      This still does in fact break the button in 2.2.0.GA! Can someone confirm this?


      I've created a test case with 3 buttons where one has no propagation, one uses s:cp tag and one uses an a4j actionparam.


      Here's the code that each tag generates:




      <a:commandButton id="discardButton1" action="#{userHome.clearInstance()}" value="Discard"
           rendered="#{userHome.managed}" ajaxSingle="true" reRender="editForm">
      </a:commandButton>
      
      <input type="button" id="editForm:discardButton1" name="editForm:discardButton1"
           onclick="A4J.AJAX.Submit('_viewRoot','editForm',event,{
                'parameters':
                     {'ajaxSingle':'editForm:discardButton1',
                      'editForm:discardButton1':'editForm:discardButton1'
                     } ,
                'actionUrl':'/TestA4j/a4jUserAdmin.seam',
                'similarityGroupingId':'editForm:discardButton1'
           } );return false;" value="Discard">






      <a:commandButton id="discardButton2" action="#{userHome.clearInstance()}" value="Discard"
           rendered="#{userHome.managed}" ajaxSingle="true" reRender="editForm">
           <s:conversationPropagation type="end" />
      </a:commandButton>
      
      <script language="JavaScript" type="text/javascript">//<![CDATA[
      var cp_discardButton2 = new Function("event", "{
        if (document.getElementById){
          var form = document.getElementById('editForm');
          var input = document.createElement('input');
          if (document.all){
            input.type = 'hidden';
            input.name = 'conversationPropagation';
            input.value = 'end';
          } else if (document.getElementById) {
            input.setAttribute('type', 'hidden');
            input.setAttribute('name', 'conversationPropagation');
            input.setAttribute('value', 'end');
          }
          form.appendChild(input);
          return true;
        }
      }");
      if (document.getElementById('editForm:discardButton2')){
        document.getElementById('editForm:discardButton2').onclick = new Function("event", "{
        if (document.getElementById){
          var form = document.getElementById('editForm');
          var input = document.createElement('input');
          if (document.all){
            input.type = 'hidden';
            input.name = 'conversationPropagation';
            input.value = 'end';
          } else if (document.getElementById) {
            input.setAttribute('type', 'hidden');
            input.setAttribute('name', 'conversationPropagation');
            input.setAttribute('value', 'end');
          }
          form.appendChild(input);
          return true;
        }
      }");
        }
      //]]>
      </script>
      <input type="button" id="editForm:discardButton2" name="editForm:discardButton2"
           onclick="cp_discardButton2();null;A4J.AJAX.Submit('_viewRoot','editForm',event,{
                'parameters':
                     {'editForm:discardButton2':'editForm:discardButton2',
                       'ajaxSingle':'editForm:discardButton2',
                       'conversationPropagation':'end'
                     } ,
                 'actionUrl':'/TestA4j/a4jUserAdmin.seam',
                 'similarityGroupingId':'editForm:discardButton2'
                } );return false;" value="Discard">




      <a:commandButton id="discardButton3" action="#{userHome.clearInstance()}" value="Discard"
           rendered="#{userHome.managed}" ajaxSingle="true" reRender="editForm">
           <a:actionparam name="conversationPropagation" value="end" />
      </a:commandButton>
      
      <input type="button" id="editForm:discardButton3" name="editForm:discardButton3" 
           onclick="A4J.AJAX.Submit('_viewRoot','editForm',event,{
                'parameters':
                     {'ajaxSingle':'editForm:discardButton3',
                      'editForm:discardButton3':'editForm:discardButton3',
                      'conversationPropagation':'end'
                } ,
                'actionUrl': '/TestA4j/a4jUserAdmin.seam',
                'similarityGroupingId':'editForm:discardButton3'
           } );return false;" value="Discard">



      So the tag creates correctly the conversationPropagation parameter inside the A4J.Submit function but it ALSO creates the full script to add a hidden input field.


      I'm not sure yet where it really fails but the A4J.Submit is never called in this case.


      And just another thing i found, the js could be a bit smaller if the functionVar is really used ;) I will file a JIRA entry once it's back on.


      <script language="JavaScript" type="text/javascript">//<![CDATA[
      var cp_discardButton2 = new Function("event", "{
        if (document.getElementById){
          var form = document.getElementById('editForm');
          var input = document.createElement('input');
          if (document.all){
            input.type = 'hidden';
            input.name = 'conversationPropagation';
            input.value = 'end';
          } else if (document.getElementById) {
            input.setAttribute('type', 'hidden');
            input.setAttribute('name', 'conversationPropagation');
            input.setAttribute('value', 'end');
          }
          form.appendChild(input);
          return true;
        }
      }");
      if (document.getElementById('editForm:discardButton2')){
        document.getElementById('editForm:discardButton2').onclick = cp_discardButton2;
      }");
        }
      //]]>
      </script>