Announcement Announcement Module
Collapse
No announcement yet.
Trapping bind errors to display as failed validation error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trapping bind errors to display as failed validation error

    Hi,

    I've successfully created validators to validate form input but I have one small issue: When a field that maps to a numeric field on command object is left blank or alfa data is entered, the following error is displayed:

    Code:
    Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property 'version'; nested exception is java.lang.NumberFormatException ...
    Where do I trap this exception and

    a) ignore it if the field is optional
    b) display a more user friendly message.

    Thanks very much. Regards,
    Stefan

  • #2
    Sorry, I omitted some info to set the stage for the question:

    I have a subclass of SimpleFormController that uses formBackingObject to get the data to display,

    it has a validator that implements validate(Object command, Errors errors) to validate the user input and rejectValue(...) to set error messages for invalid user input

    and it uses onSubmit to save the user input.

    Regards,
    Stefan

    Comment


    • #3
      a) I don't think you can 'ignore' the error, if the user enters data for the field, the binder will try to bind it and you will get some error if that fails.

      b) Check the JavaDoc for DataBinder, DefaultMessageCodesResolver and MessageTag.

      BTW: SimpleFormController related questions should go in the "Web" forum, since they do not relate to Spring Web Flow.

      Erwin

      Comment

      Working...
      X