views:

9

answers:

0

Is there a way to validate a collection other than using the visitor validator?

Let's say that I'm validating just primitive data and not a domain model object. For the next example how the 7 following inputs can get validated for "required". The only way that I believe I can do that is programatically in the validate() of the Action but how to handle the indexed collection that in the case of a validation error the corresponding input field gets the appropriate message.

Giving the following example: ageCollector.jsp:

<s:form action="saveAges">
        <s:bean name="org.apache.struts2.util.Counter" var="counter">
            <s:param name="last" value="7"/>
        </s:bean>
        <s:iterator value="#counter" status="status">
            <s:textfield label="Age" name="%{'age[' + #status.count + ']'}" />
        </s:iterator>
</s:form>

And the following action

public class SaveAges extends ActionSupport {

    public String execute() {
      return SUCCESS;
    }

    private List<Integer> ages;
    //setters and getters....
}

Any thoughts?

Thank you.