How to validate that date in future in reference to another date?

gstackoverflow picture gstackoverflow · Apr 17, 2015 · Viewed 10.2k times · Source

I have following bean:

class CampaignBeanDto {

    @Future
    Date startDate;

    Date endDate;

    ...
}

Obviously I that endDate should be after startDate. I want to validate it.

I know that I can manually realize annotation for @FutureAfterDate, validator for this and initialize threshold date manually but I want to use @Validated spring mvc annotation.

How can I achieve it?

Answer

Neil McGuigan picture Neil McGuigan · Apr 17, 2015

You're gonna have to bear down and write yourself a Validator.

This should get you started:

Cross field validation with Hibernate Validator (JSR 303)