I have a bean which references a collection of other beans. I use @Valid
to include all referenced beans in the validation.
public class MasterBean {
@Valid
private Collection<DetailBean> details;
...
}
public class DetailBean {
private String id;
@NotBlank(message = "{name_not_blank_message_key}")
private String name;
...
}
This works fine so far, the user gets all validation error messages from all DetailBean
instances. However, the error messages do not contain any indication about which of the instances they are related to. Ideally, the user should see something like "Name of something is missing", where something is a property (e.g. id
) of the given instance.
Unfortunately the stock MessageInterpolator allows placeholders for static annotation parameters only (like {min}
) and does not support the substitution of bean properties.
I've read several related posts, maybe this one being the closest, but none of the suggestions seems to be feasible in my case (besides an own MessageInterpolator implementation - what I'm more than afraid of...).
Some more background: I'm working on a JSF 2 project with the extensive use of RichFaces tags. The bean to be validated is part of the backing bean of a JSF page, validation is triggered by a <rich:graphValidator>
tag upon form submission. The back-end is Hibernate Validator.