1 Reply Latest reply on Dec 27, 2009 4:57 PM by Max Meyers

    AJAX submit - updating model values

    Max Meyers Newbie

      Hi!


      I have a problem with an ajax submit. The problem is in the following piece of code:




      <a:repeat id="agRepeater"
           value="#{TrialFormEditor.notHiddenAttributeGroups}" var="_ag"
           rowKeyVar="row">
           <div><rich:spacer height="15" width="1" /></div>
           <a:form id="newGroupForm" ajaxSubmit="true" status="globalStatus"
                reRender="outputer4agRepeater" oncomplete="bindJQuery();">
                <h:graphicImage
                     value="#{RuntimeConfiguration.imagePrefix}graphics/button/add_small.png"
                     title="#{messages['button.addGroup']}"
                     alt="#{messages['button.addGroup']}"
                     onmouseover="this.src='#{RuntimeConfiguration.imagePrefix}graphics/button/add_small_hover.png'; this.style.cursor='pointer';"
                     onmouseout="this.src='#{RuntimeConfiguration.imagePrefix}graphics/button/add_small.png'"
                     onclick="jQuery('#agRepeater\\\\:#{row}\\\\:newGroupForm\\\\:groupAdd').fadeIn('slow'); jQuery('#agRepeater\\\\:#{row}\\\\:newGroupForm\\\\:groupAddTf').focus();" />
      
                <rich:spacer width="5" />
      
                <s:span id="groupAdd" style="display: none; vertical-align: 50%;">
                     <h:inputText id="groupAddTf"
                          value="#{TrialFormEditor.newAttributeGroupName[_ag.sort]}" />
                     <rich:spacer width="5" />
                     <h:commandButton value="#{messages['button.add']}"
                          action="#{TrialFormEditor.insertGroup(_ag)}" />
                </s:span>



      As you can see I am using an array for the value binding (newAttributeGroupName). If the form gets submitted the value of newAttributeGroupName is only updated for the last element (i.e. the last iteration). Thus this works only, if the last ajax form of the iteration is used.


      Example:





      newAttributeGroupName[0] = actual: 'New Group', user input: 'something' --> not updated on submit (get 'New Group' in bean)

      newAttributeGroupName[1] = actual: 'New Group', user input: 'something' --> not updated on submit (get 'New Group' in bean)

      newAttributeGroupName[2] = actual: 'New Group', user input: 'something' --> updated on submit (get 'something' in bean)


      I don't know what's special about the last iteration (why it's working). Here is the full view and bean code. It's a little bit confusing,that the model value is only updated for the last element of my a4j:repeat loop.


      I hope it's somewhat understandable.


      regards,
      Max.

        • 1. Re: AJAX submit - updating model values
          Max Meyers Newbie

          Now I've looked at the generated html and it's a little bit crazy. JSF generated two times the same code only with an other index and for one it's working and for the other one not. It's a little bit confusing, what happens internally, so that two times the same code has different behaviour.


          Here is the generated html:


          Index two (not working)

          Index four (working)


          I analyzed it with a diff tool, but couldn't recognize any difference (except the index of the a:repeat loop).


          Is this a bug? Do I need to nest the form into another component? Does anyone have suggestions?


          Thank you!


          regards,
          Max.