Hi all,
I have a command object looking like this:
and here is an Event validator exempleCode:class Event { Date date; Person manager; List<Person> people; }
and a PersonValidator example:Code:public void validate(Object command, Errors errors) { LOGGER.debug("validating..."); Event event = (Event) command; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "date", "error.evennt.date.empty"); } }
This is a simplified example, just to expose the problem. In reality, my Person class is used in a lot of Controller, and has to be validated in several ways depending some parameters.Code:public void validate(Object command, Errors errors) { LOGGER.debug("validating..."); Person person = (Person) command; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.person.name.empty); } }
My problem is that I want to validate my Event using a validator, and then invoking a validator for Person, and all the Person in my people list, then display these errors on my form.
Is there a clean way to invoke the PersonValidator from the event validator passing him a prefix (in my previous case it has to be "manager.name" or "manager" in fact, to ensure that the errors object will be populated with the complete properties names ?
I'am not sure to be clear enough
What I can do now is this:
Code:public void validate(Object command, Errors errors) { LOGGER.debug("validating..."); Event event = (Event) command; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "date", "error.event.date.empty"); PersonValidator pv = new PersonValidator(); ValidationUtils.invokeValidator(pv, event.getManager(), errors); } }
and What I want to be done is this:
Last line is important: MyValidationUtils.invokeValidator takes an additional parameter.
And I was wondering why this is not default in SpringMVC ?Code:public void validate(Object command, Errors errors) { LOGGER.debug("validating..."); Event event = (Event) command; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "date", "error.event.date.empty"); PersonValidator pv = new PersonValidator(); MyValidationUtils.invokeValidator(pv, event.getManager(), errors, "manager"); } }
Please comment!



!
Reply With Quote
Sami