Announcement Announcement Module
Collapse
No announcement yet.
How to display only one error message for 2 error codes? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display only one error message for 2 error codes?

    In the page, user can input a double value with 2 text input fields. For example, user can input 3 in the first input field and 15 in the second input field, and the result will be 3.15.

    However, if the user input 'a' in the first input field and 'b' in the second input, Spring will generate 2 typeMismatch error codes and will display 2 error messages in the page.

    Unfortunately, customer only want one error message displayed for the whole value.

    And I cannot remove the error code from Errors or BindException since Spring doesn't provide such API. :cry:

    One solution is to define the 2 properties as String in the form object, and provide customized validator. But I don't like this solution since the 2 fields are surely integers in the domain.

  • #2
    Why not insert your ResourceBundleMessageSource into your controller, and add the error message to your model? E.g.

    Code:
    if (errors.hasFieldErrors("integerPart") || errors.hasFieldErrors("fractionPart) {
        model.put("error", getDeimalErrorMessagFromResourceBundleMessageSource());
    }
    You can then display this message, and not the bind ones.

    Comment

    Working...
    X