Announcement Announcement Module
No announcement yet.
Question about annotated controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about annotated controller


    I have a small issue concerning the usage of the annotated controllers. Is there a way to catch the wrong binding to the modelattribute. Let say that a property expects an 'int' but the user typed a String value in the input field.
    What I need is to catch this an error so it will be placed inside the BindingResult object. In this case, I can display a proper message towards the user instead of an ugly stacktrace on the screen.

    Last edited by Krycek_A; Jun 30th, 2008, 05:08 AM.

  • #2
    I suggest you readup on how to modify those messages. You don't have to do much for that.

    First you have to realize that this kind of exception is ALREADY being added to the BindingResult. Next realize that spring uses a MessageSource to convert error codes into proper messages (if nothing found a default will be displayed, that is what you see currently).

    So to make it work. define a MessageSource (see the javadocs for implementations) in your ApplicationContext and create a properties file the error codes are generated by a MessageCodeResolver. Which currently has one implementation (see the javadoc).


    • #3
      Thank you for the quick reply, I will try this definitely out