Announcement Announcement Module
Collapse
No announcement yet.
Custom bind error messages. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom bind error messages.

    I've searched the forum, but I think this is a bit to simple so no one has come right out and said it yet. Basicly, when my date binding fails, how do I display a pretty message instead of the default verbose one? I think I have to put a .properties file somewhere, I just don't know where or what format to use. Thanks!

  • #2
    Take a look at the Javadoc for org.springframework.validation.DefaultMessageCodes Resolver.

    There are example messages that handle improperly entered dates in Petclinic's messages.properties.

    The Petclinic source is in the samples/petclinic dir of the download.

    Comment


    • #3
      So, I've got a messages.properties file in WEB-INF\classes with one line:

      typeMismatch=invalid date

      but whatever is supposed to be reading it, isn't. I've looked at the petstore source, and it looks like it works for them by merely having the file exist in that directory. Is there anything else I need to do?

      Comment


      • #4
        You have to define a messageSource bean in your context. In the sample app, it is defined in petclinic-servlet.xml

        Code:
        	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        		<property name="basename"><value>messages</value></property>
        	</bean>
        see also : http://www.springframework.org/docs/...-messagesource

        Maarten

        Comment


        • #5
          Yea, I found that and added the bean definition, copy and paste, to my application context. I'm wondering if I just have my messages.properties file in the wrong place.

          Comment

          Working...
          X