Does roo not yet wire up Error messages from user defined constraints at the web tier?
Here's the log from when validation fails:
My bean looks something like this:Code:Invoking request handler method: public java.lang.String noticeservice.domain.NoticeController.create(noticeservice.domain.Notice,org.springframework.validation.BindingResult,org.springframework.ui.ModelMap) ValidationMessages not found. Delegating to org.hibernate.validation.ValidationMessages Cannot find javax.persistence.PersistenceUtil on classpath. All properties will per default be traversable. No META-INF/validation.xml found. Using annotation based configuration only! ValidationMessages not found. Delegating to org.hibernate.validation.ValidationMessages Invoking init-binder method: public void noticeservice.domain.NoticeController.initBinder(org.springframework.web.bind.WebDataBinder) Requested media types are [text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8] (based on Accept header) Returning [org.springframework.web.servlet.view.tiles2.TilesView: name 'notice/create'; URL [notice/create]] based on requested media type 'text/html' Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'notice/create'; URL [notice/create]] in DispatcherServlet with name 'noticeservice' Added model object 'notice' of type [noticeservice.domain.Notice] to request in view with name 'notice/create' Added model object 'org.springframework.validation.BindingResult.notice' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'notice/create' Added model object 'org.springframework.validation.BindingResult.objectError' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'notice/create' Added model object 'objectError' of type [org.springframework.validation.ObjectError] to request in view with name 'notice/create' Render request recieved for definition 'notice/create' Successfully completed request
and the constraint looks something like:Code:@Entity @RooJavaBean @RooToString @RooEntity(finders = { "findNoticesByStartDateGreaterThanAndEndDateLessThan" }) @StartDateBeforeEndDate() // Custom constraint public class Notice { @NotNull private Date startDate; @NotNull private Date endDate; }
There's nothing special about the Validator either:Code:@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Documented @Constraint(validatedBy = StartDateBeforeEndDateValidator.class) public @interface StartDateBeforeEndDate { String message() default "startDate must be before endDate"; Class<?>[] groups() default {}; Class<? extends ConstraintPayload>[] payload() default {}; }
Am I going about this the wrong way? Maybe I should use a checkCoherence sort of method with an @AssertTrue, but will that work on the web tier?Code:public class StartDateBeforeEndDateValidator implements ConstraintValidator<StartDateBeforeEndDate, Notice> { @Override public void initialize(StartDateBeforeEndDate constraintAnnotation) { // Do nothing... } @Override public boolean isValid(Notice notice, ConstraintValidatorContext context) { if (notice == null) return true; return notice.getStartDate().before(notice.getEndDate()); } }


Reply With Quote
