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..validation.BindingResult,org..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..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..web.servlet.view.tiles2.TilesView: name 'notice/create'; ucl [notice/create]] based on requested media type 'text/html'
Rendering view [org..web.servlet.view.tiles2.TilesView: name 'notice/create'; ucl [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..validation.BindingResult.notice' of type [org..validation.BeanPropertyBindingResult] to request in view with name 'notice/create'
Added model object 'org..validation.BindingResult.objectError' of type [org..validation.BeanPropertyBindingResult] to request in view with name 'notice/create'
Added model object 'objectError' of type [org..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 = { quot;findNoticesByStartDateGreaterThanAndEndDateLessThanquot; })
@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 quot;startDate must be before endDatequot;;
Classlt;?gt;[] groups() default {};
Classlt;? extends ConstraintPayloadgt;[] payload() default {};
}
There's nothing special about the Validator either:
Code:
public class StartDateBeforeEndDateValidator implements ConstraintValidatorlt;StartDateBeforeEndDate, Noticegt; {
@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?
Validation works, it's just that the error is not displayed.
Filed issue browse/ROO-360
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
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.
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:
lt;form:input cssStyle=quot;width:250pxquot; id=quot;_street_idquot; maxlength=quot;30quot; path=quot;streetquot; size=quot;0quot;/gt;
Is that a bug or am I missing something? |