2 Replies Latest reply on Sep 27, 2007 12:06 PM by crabb

    problems with a4j inside a dataTable when validation errors

    crabb

      I am having some issues when using a4j:support (event=onchange) inside a dataTable when the item being changed has validation errors. If the same widget is disabled on another row in the dataTable, those disabled widgets are updated with the data from the invalid entry.

      Following is a simple example with the jsf page and the backing bean

      <f:view>
       <html>
       <body>
       <h:form>
       <h:commandButton action="#{testBacking.test}" value="refresh"/>
       <h:dataTable var="number" value="#{testBacking.numbers}">
       <h:column>
       <h:inputText id="original" value="#{number.value}" disabled="#{number.readOnly}">
       <a4j:support event="onchange" reRender="mirror">
       <a4j:ajaxListener type="org.ajax4jsf.ajax.ForceRender" />
       </a4j:support>
       </h:inputText>
       <a4j:outputPanel ajaxRendered="true">
       <h:message for="original"/>
       </a4j:outputPanel>
       </h:column>
       <h:column>
       <h:outputText id="mirror" value="#{number.value}"/>
       </h:column>
       </h:dataTable>
       </h:form>
       </body>
       </html>
      </f:view>
      


      And the backing bean:

      public class TestBacking
      {
       private ArrayList numbers;
       private ListDataModel numbersModel;
      
       {
       numbers = new ArrayList();
       numbers.add(new TestNumber(1, true));
       numbers.add(new TestNumber(2, true));
       numbers.add(new TestNumber(3, true));
       numbers.add(new TestNumber(4, false));
       numbers.add(new TestNumber(5, false));
       numbersModel = new ListDataModel(numbers);
       }
      
       public ListDataModel getNumbers()
       {
       return numbersModel;
       }
      
       public String test()
       {
       return "test"; // return back to same page
       }
      
       public static class TestNumber
       {
       int value;
       boolean readOnly;
      
       public TestNumber(int value, boolean readOnly)
       {
       this.value = value;
       this.readOnly = readOnly;
       }
      
       public int getValue() {return value;}
       public void setValue(int value) {this.value = value;}
       public boolean isReadOnly() {return readOnly;}
       }
      }
      


      This code basically will render a table with 5 rows. The first three rows have an inputText that is disabled. When I enter an invalid number in the fourth row (such as "f") and click out, a validation message shows appropriately. However, if I then click the refresh button, you can see that the disabled rows were also updated with "f"... if I now change to a valid number and click refresh, all disabled rows are updated with the same number.

      Can anyone provide some insight here? Is this a know issue with a4j? Is there a work around or something I can do to resolve the issue?