Announcement Announcement Module
No announcement yet.
Roo and User Constraints Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo and User Constraints

    Does roo not yet wire up Error messages from user defined constraints at the web tier?

    Here's the log from when validation fails:
    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
    My bean looks something like this:
    @RooEntity(finders = { "findNoticesByStartDateGreaterThanAndEndDateLessThan" })
    @StartDateBeforeEndDate() // Custom constraint
    public class Notice {
        private Date startDate;
        private Date endDate;
    and the constraint looks something like:
    @Constraint(validatedBy = StartDateBeforeEndDateValidator.class)
    public @interface StartDateBeforeEndDate {
    	String message() default "startDate must be before endDate";
    	Class<?>[] groups() default {};
    	Class<? extends ConstraintPayload>[] payload() default {};
    There's nothing special about the Validator either:
    public class StartDateBeforeEndDateValidator implements ConstraintValidator<StartDateBeforeEndDate, Notice> {
    	public void initialize(StartDateBeforeEndDate constraintAnnotation) {
    		// Do nothing...
    	public boolean isValid(Notice notice, ConstraintValidatorContext context) {
    		if (notice == null)
    			return true;
    		return notice.getStartDate().before(notice.getEndDate());
    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?

  • #2
    Validation works, it's just that the error is not displayed.

    Filed issue


    • #3

      Thanks for raising this. Indeed I was already considering to put in a 'catch all' error panel so all errors which are not related to fields are displayed as well. I was thinking presenting an inner title pane in the view which is collapsed by default. So the interested user can open it up to see the details. Other ideas?



      • #4
        I would leave it open by default. If it's an input, validation or data integrity type error (As opposed to, say a RuntimeException) the user will mostly care about it, imho.

        That said, though, my orginal use case was 'start date before end date', but I have since figured out how to assign that error to a field.


        • #5
          Length Constraints


          I also noticed, that when you specify a length constraint, the maxlength field for inputs on the ui is not adjusted.

          public class Customer {
              @Size(min=0, max=120)
              private String street;
          <form:input cssStyle="width:250px" id="_street_id" maxlength="30" path="street" size="0"/>
          Is that a bug or am I missing something?