Results 1 to 5 of 5

Thread: Roo and User Constraints

  1. #1
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    97

    Default 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:
    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
    My bean looks something like this:
    Code:
    @Entity
    @RooJavaBean
    @RooToString
    @RooEntity(finders = { "findNoticesByStartDateGreaterThanAndEndDateLessThan" })
    @StartDateBeforeEndDate() // Custom constraint
    public class Notice {
    
        @NotNull
        private Date startDate;
    
        @NotNull
        private Date endDate;
    
     
    }
    and the constraint looks something like:
    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 {};
    
    }
    There's nothing special about the Validator either:
    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());
    
    	}
    
    }
    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. #2
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    97

    Default

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

    Filed issue http://jira.springframework.org/browse/ROO-360

  3. #3
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Haikal,

    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?

    -Stefan

  4. #4
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    97

    Default

    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. #5

    Question Length Constraints

    Hi,

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

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •