This issue can't be edited
Because it belongs to an archived project. Jira admins can restore projects from the archive.
Revisit cross field validation
Description
Environment
Attachments
Activity
Leo Luo January 30, 2023 at 1:32 AMEdited
Should have. Many JavaBeans have an approval status (pending submission, being approved, approved, rejected) and a rejection reason. When the approval status is rejected, the rejection reason is required, and other statuses are not required. Is there an elegant way to handle it?
Luís Alves August 24, 2022 at 4:22 PM
I think would be enough if ConstraintValidatorContext
could provide a reference for the object the field belongs to. Then the BV custom implementation can decide what to do with it. For example with Spring we could use SpEL and do validation on a field that uses information from another field or fields on the bean. The current solution with class level validation works, but you lose the the actual path of the validated field that can be inside a list and should have a proper index. On Vivian Steller example if b as a list of Integers if you had 10 items and only 2 failed the validation you cannot tell which ones were with class level validation, if I’m not mistaken.
Vivian Steller June 14, 2012 at 10:22 AM
what's the status on this? any chance to get something done in this area for BV1.1?
I'd really like be able to have cross-field validation annotations on property level rather than solely on class level. Consider the following example, which is really ugly in my opinion if implemented on bean level:
Consider @Max
would be a binary constraint, allowing to reference another property that provides the maximum value. This is what I would like to do:
Implementing this on bean level is really ugly, isn't it?:
I know, using @ScriptAssert
might make the second version more readable, however, it's the same issue if you have large beans with more cross-level constraints. IMO @Max("#{a}")
is not only the most readable but also much more consistent with the unary @Max
constraint.
Gunnar Morling September 26, 2011 at 10:38 PM
Should have. Was one of the most frequently raised questions I heard when talking about BV.
Cross field validation is addressed via a black box model using class-level constraint validators. While conceptually elegant, many people have asked for a way to place such field validation at field level and offer the ability to reach the value of another field from there. Cross field validation is also a need in presentation layers like JSF.
Let's reopen the debate if time permits.