2 Replies Latest reply on Oct 18, 2007 7:53 AM by ilya_shaikovsky

    Questions about a4j:support

    romaintaz

      Hi,

      I am using RichFaces 3.1.2.

      I have two questions about the component <a4j:support>:

      1. Let's consider the following code:

      <h:inputText value="#{myBean.inputValue}">
       <a4j:support event="onchange" action="#{myBean.doChangeResult}" reRender="..."/>
      </h:inputText>
      


      This code works correctly and generate the following HTML code:

      <input type="text" name="myForm:j_id53" onchange="A4J.AJAX.Submit('_viewRoot','myForm',event,{'parameters':{'myForm:j_id54':'myForm:j_id54'} ,'actionUrl':'/.../todolist.jsf'} )"/>


      Good. Now, I set an onchange attribute to my inputText:

      <h:inputText value="#{myBean.inputValue}" onchange="alert('test');">
       <a4j:support event="onchange" action="#{myBean.doChangeResult}" reRender="..."/>
      </h:inputText>
      


      The generated HTML code is then:

      <input type="text" name="myForm:j_id53" onchange="alert('test');" />

      Why the a4j:status does not append its Javascript call to the existing onchange value?
      In fact, I expected to have something like that:

      <input type="text" name="myForm:j_id53" onchange="alert('test');A4J.AJAX.Submit('_viewRoot','myForm',event,{'parameters':{'myForm:j_id54':'myForm:j_id54'} ,'actionUrl':'/.../todolist.jsf'} )"/>


      2. I have developed a component (called <my:validation/> that modifies the onchange and onblur attribute of its parent.
      When I write this code:

      <h:inputText value="#{myBean.inputValue}">
       <a4j:support event="onchange" action="#{myBean.doChangeResult}" reRender="..."/>
       <my:validation/>
      </h:inputText>
      


      it creates the following HTML code:


      <input type="text" name="myForm:j_id53" onblur="return checkRequired(this, 'This field is required.');" onchange="hideAlarm(this);A4J.AJAX.Submit('_viewRoot',null,event,{'parameters':{'j_id54':'j_id54'} ,'actionUrl':'/.../mytodolist.jsf'} )"/>

      What is strange is that the a4j:support creates the correct Javascript call, except that it does not found the form that contains my inputText. Then, the Ajax call is sent, but with errors, a4j:log shows me that:

      debug[14:34:28,183]: NEW AJAX REQUEST !!! with form :null

      Why does the <a4j:support> does not find the form?

      For your information, my component modifies its parent's Javascript attribute when the method setParent (of my component) is called.


        • 1. Re: Questions about a4j:support
          romaintaz

          Concerning the problem #2:

          When the method setParent(UIComponent) is called on my component, the onchange attribute value of my input field is:
          A4J.AJAX.Submit('_viewRoot',null,event, ...

          When the encodeBegin(...) method is called, this value is then:
          A4J.AJAX.Submit('_viewRoot', myForm,event, ...
          which is correct.

          In other words, it seems that <a4j:support> resolves the form ID after the setParent() is called on my component, and before encodeBegin() is called.

          So, if I modify the parent of my component during its encodeBegin() instead of during setParent(), it works as expected...

          Now, what about my problem #1 ?

          • 2. Re: Questions about a4j:support
            ilya_shaikovsky

            Concerning the problem 1. Works as designed. you should use onsubmit or oncomplete on the support component to call JS before or after the requests.