References: * https://stackoverflow.com/questions/50214195/validating-a-subset-of-list-items-using-java-hibernate-aquiring-the-full-proper * https://discourse.hibernate.org/t/how-can-i-retrieve-current-validation-contexts-groups-in-a-validator/414/4
This was requested by different users 2 times in a row so it's definitely something that could be useful. Currently, we have a workaround by using a {{DefaultGroupSequenceProvider}} but a more natural way to do it would be welcome.
We should be able to: * decide if we trigger the validation for the/one of the cascaded object(s) depending on the cascaded object itself: not sure this would be easy as you could have a container, in which case you should consider each element of the container (we would probably need to add the annotation at the container level). * decide if we trigger the cascading entirely depending on the cascading object.
Something like: {code} class CascadingObject { @Valid // probably would be the default in this case. @ValidPredicate(target = CASCADING_OBJECT, value = MyPredicateOnCascadingObject.class) private CascadedObject cascadedObject; {code}
{code} class CascadingObject { @Valid @ValidPredicate(target = CASCADED_OBJECT, value = MyPredicateOnCascadedObject.class) private CascadedObject cascadedObject; {code}
{code} class CascadingObject { // no need to define the target as in this case, there's no doubt about the target private List<@Valid @ValidPredicate(MyPredicateOnCascadedObject.class) CascadedObject> cascadedObject; {code}
We could think about specifying it later and have: {code} @Valid(predicate = { @ValidPredicate(MyPredicateOnCascadingObject.class) }) {code}
Additional info from the OP's case: {quote} I am in the process of implementing the GroupSequenceProvider. My only question is can I access the Parent Object information (in this case Booking) within the Journey GroupSequenceProvider, so I can identify if the index position of the Journey object is less than the Booking.totalJourneys value? {quote}
Given this additional information, what I proposed above won't solve the OP's case. It might work if we add various methods to the predicate to allow for the different {{ValueExtractor}}'s cases and provide the cascading object, the cascaded one and the index for instance. Not sure how we could make that pretty though... |
|