Custom validator comparing two fields
I have two DateFields, startDate and endDate.
I want to write a validator that checks that startDate should be smaller than endDate and vice versa.
The Validator interface however only accepts one field and one value.
What's the best way to implement the this check?
One option would be to make the validator implementation's constructor accept as an argument the second field to compare against. Then, make a new instance of the validator for each field, pointing at the corresponding field that it needs to work with to behave correctly.
Another option would be to just make an anonymous subclass, and as long as the other field is made final (or an instance variable), refer to it within the implementation.
Thanks, solved by putting the required fields into the constructor.
Tags for this Thread