Nicolas Bouillon created TAP5-2475:
--------------------------------------

             Summary: Form Field in Loop : on validation error all field get 
the same value
                 Key: TAP5-2475
                 URL: https://issues.apache.org/jira/browse/TAP5-2475
             Project: Tapestry 5
          Issue Type: Bug
          Components: tapestry-core
    Affects Versions: 5.4
            Reporter: Nicolas Bouillon
            Priority: Blocker


On 5.4-beta-26.

Given a template like this :

{code:xml}
<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>
{code}

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

{code:title=Index.java|borderStyle=solid}
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());
        }
    }
}
{code}

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



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to