Results 1 to 2 of 2

Thread: How to display only one error message for 2 error codes?

  1. #1
    Join Date
    May 2005
    Location
    Shanghai, China
    Posts
    7

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    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.

Similar Threads

  1. Display tree on JSP, recursion?
    By pak in forum Web
    Replies: 3
    Last Post: Jul 9th, 2011, 02:20 AM
  2. How to display message about last action?
    By pir8ped in forum Architecture
    Replies: 8
    Last Post: Jun 6th, 2005, 11:01 AM
  3. Replies: 1
    Last Post: Apr 28th, 2005, 01:54 PM
  4. Replies: 0
    Last Post: Jan 22nd, 2005, 07:28 AM
  5. Replies: 2
    Last Post: Dec 18th, 2004, 10:33 AM

Posting Permissions

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