Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-2475

Form Field in Loop : on validation error all field get the same value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Cannot Reproduce
    • 5.4
    • 5.4
    • tapestry-core

    Description

      On 5.4-beta-26.

      Given a template like this :

      <t:form t:id="form">
              <t:errors/>
              <t:loop source="items" value="item">
                  <div>
                      <t:label for="field"/>
                      <t:textfield t:id="field" value="value" label="prop:item"/>
                  </div>
              </t:loop>
              <div>
                  <t:submit/>
              </div>
          </t:form>
      

      If the validation of the form fails (global validation), the page is displayed with all the field containing the same value, the last one.

      Index.java
      public class Index {
      
          private Map<String, String> values;
      
          @Property
          private String item;
      
          public String[] getItems() {
              return new String[]{"one", "two", "three"};
          }
      
          public void setValue(String value) {
              if (values == null) {
                  values = new LinkedHashMap<>();
              }
              values.put(item, value);
          }
      
          public String getValue() {
              if (values == null) {
                  values = new LinkedHashMap<>();
                  for (String item : getItems()) {
                      values.put(item, item);
                  }
              }
              return values.get(item);
          }
      
          @Inject
          private AlertManager alertManager;
      
          @InjectComponent
          private Form form;
      
          public void onValidateFromForm() {
              form.recordError("Purposely generated error");
          }
      
          public void onSuccessFromForm() {
              for (Map.Entry<String, String> entry : values.entrySet()) {
                  alertManager.info(entry.getKey() + " = " + entry.getValue());
              }
          }
      }
      

      Any help will be welcomed to guide me to provide a patch.

      Attachments

        1. tapestry-test.zip
          5 kB
          Nicolas Bouillon

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bouil Nicolas Bouillon
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: