AJAX submit - updating model values
maxseam Dec 26, 2009 1:50 AMHi!
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.