0
votes

What I'm trying to accomplish is:

Have a bean backed form being validated, for example using the following class

public class PersonForm {

    @NotNull
    String name;

    List<Long> interests;

    // This attribute is not filled out in the form
    List<Interest> realInterests;
}

So, "name" and "interests" come from the web form. "name" has some constrains (NotNull) and using @Valid does what it is supposed to do.

"interests" is a list of Interest ids.

After doing the initial validation of the "name" I fill out the List collection.

@CustomValidInterest
public class Interest {

    Long id;
    String name;
    boolean available;

}

I want to validate this structure afterwards. "@CustomValidInterest" is a custom validation annotation. I can do a 2-stage validation using do this with Validation Groups.

The problem is, if some "Interest" object is not valid I want to associate the error message with the "interests" field (List< Long > type), so when I retrieve the form errors the error is associated with the right field.

Maybe I'm trying to use validation the wrong way. I was trying to avoid having a bunch of programmatic comparisons which filled errors manually.

1

1 Answers

0
votes

Answering my own question, this is achievable using PropertyEditors. The form might return a List< Long > but the form object can have only a List < Interest > which is built using said Property mapper. After that a @Valid on that list should validate any constraints that "Interest" enforces.