Spring Roo
  1. Spring Roo
  2. ROO-360

Default Roo created templates do not display Object level validation errors.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0.RC2
    • Fix Version/s: 1.0.0.RC4
    • Component/s: WEB MVC
    • Labels:
      None

      Description

      The default template does not display error messages for object level validation failures.

      The controller does save them:

      Added model object 'org.springframework.validation.BindingResult.objectError' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'notice/create'

      It's just they're not displayed to the user.

        Activity

        Hide
        Haikal Saadh added a comment -

        A better idea may be to actually direct the error to a specific field in the validator: https://forum.hibernate.org/viewtopic.php?f=26&t=998743

        Show
        Haikal Saadh added a comment - A better idea may be to actually direct the error to a specific field in the validator: https://forum.hibernate.org/viewtopic.php?f=26&t=998743
        Hide
        Stefan Schmidt added a comment -

        Haikal,

        Would you be able to attach a sample project which causes this validation issue?

        -Stefan

        Show
        Stefan Schmidt added a comment - Haikal, Would you be able to attach a sample project which causes this validation issue? -Stefan
        Hide
        Haikal Saadh added a comment -

        I've added a hardcoded-to-fail validator to the Rsvp entity of wedding.roo.

        When you try and RSVP now, you should see this in the log:

        DispatcherServlet with name 'wedding' processing POST request for [/wedding/app/rsvp]
        Mapping [/rsvp] to handler 'com.wedding.web.RsvpController@52977e69'
        Invoking init-binder method: public void com.wedding.web.RsvpController.initBinder(org.springframework.web.bind.WebDataBinder)
        Invoking request handler method: public java.lang.String com.wedding.web.RsvpController.create(com.wedding.domain.Rsvp,org.springframework.validation.BindingResult,org.springframework.ui.ModelMap)
        Hibernate Validator 4.0.0.Beta2
        No META-INF/validation.xml found. Using annotation based configuration only!
        Invoking init-binder method: public void com.wedding.web.RsvpController.initBinder(org.springframework.web.bind.WebDataBinder)
        Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'rsvp/create'; URL [rsvp/create]] in DispatcherServlet with name 'wedding'
        Added model object 'rsvp' of type [com.wedding.domain.Rsvp] to request in view with name 'rsvp/create'
        Added model object 'org.springframework.validation.BindingResult.objectError' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'rsvp/create'
        Added model object 'objectError' of type [org.springframework.validation.ObjectError] to request in view with name 'rsvp/create'
        Added model object 'org.springframework.validation.BindingResult.rsvp' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'rsvp/create'
        Successfully completed request
        Show
        Haikal Saadh added a comment - I've added a hardcoded-to-fail validator to the Rsvp entity of wedding.roo. When you try and RSVP now, you should see this in the log: DispatcherServlet with name 'wedding' processing POST request for [/wedding/app/rsvp] Mapping [/rsvp] to handler 'com.wedding.web.RsvpController@52977e69' Invoking init-binder method: public void com.wedding.web.RsvpController.initBinder(org.springframework.web.bind.WebDataBinder) Invoking request handler method: public java.lang. String com.wedding.web.RsvpController.create(com.wedding.domain.Rsvp,org.springframework.validation.BindingResult,org.springframework.ui.ModelMap) Hibernate Validator 4.0.0.Beta2 No META-INF/validation.xml found. Using annotation based configuration only! Invoking init-binder method: public void com.wedding.web.RsvpController.initBinder(org.springframework.web.bind.WebDataBinder) Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'rsvp/create'; URL [rsvp/create]] in DispatcherServlet with name 'wedding' Added model object 'rsvp' of type [com.wedding.domain.Rsvp] to request in view with name 'rsvp/create' Added model object 'org.springframework.validation.BindingResult.objectError' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'rsvp/create' Added model object 'objectError' of type [org.springframework.validation.ObjectError] to request in view with name 'rsvp/create' Added model object 'org.springframework.validation.BindingResult.rsvp' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'rsvp/create' Successfully completed request
        Hide
        Haikal Saadh added a comment -

        A strategically placed <form:error path="*" /> is all that's needed to fix this.

        Show
        Haikal Saadh added a comment - A strategically placed <form:error path="*" /> is all that's needed to fix this.
        Hide
        Stefan Schmidt added a comment -

        Haikal,

        I have included a <form:error /> element on top of the forms for create and updated jspx files. Leaving out the path parameter gives us access to ObjectError as opposed to FieldError (which are mapped to the relevant form fields) and therefore we can avoid having duplication of errors.

        In short all object errors will be displayed above the form and field errors will be presented in line with the form fields.

        This improvement is available as of revision 440 in Roo trunk.

        Cheers,
        -Stefan

        Show
        Stefan Schmidt added a comment - Haikal, I have included a <form:error /> element on top of the forms for create and updated jspx files. Leaving out the path parameter gives us access to ObjectError as opposed to FieldError (which are mapped to the relevant form fields) and therefore we can avoid having duplication of errors. In short all object errors will be displayed above the form and field errors will be presented in line with the form fields. This improvement is available as of revision 440 in Roo trunk. Cheers, -Stefan

          People

          • Assignee:
            Stefan Schmidt
            Reporter:
            Haikal Saadh
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: