model view controller - spring 3.0 MVC seems to be ignoring messages.properties -
spring 3.0 mvc
first of all, haven't found documentation regarding messages.properties @ springsource i've found overriding error messages has been on various forums. if has reference messages.properties documented that'd fantastic. maybe messages.properties comes not spring java spec?
i have tried following advice on jsr-303 type checking before binding goal replace type mismatch error messages own user friendly error messages
my situation follows:
model
public class test { private int numberbomb; public int getnumberbomb() { return numberbomb; } public void setnumberbomb(int numberbomb) { this.numberbomb = numberbomb; } }
myservlet.xml
<mvc:annotation-driven/>
jsp
<form:form id="test" method="post" modelattribute="test"> <form:errors path="*"/> <form:label path="numberbomb">numberbomb</form:label> <form:input path="numberbomb"/> </form:form>
classes\messages.properties
typemismatch=bad value bad bad person test.numberbomb=you driving me crazy these bad inputs
output form
failed convert property value of type java.lang.string required type int property numberbomb; nested exception org.springframework.core.convert.conversionfailedexception: unable convert value "three" type java.lang.string type int; nested exception java.lang.numberformatexception: input string: "three"
bindingresult.tostring() within controller
field error in object 'test' on field 'numberbomb': rejected value [three]; codes [typemismatch.test.numberbomb,typemismatch.numberbomb,typemismatch.int,typemismatch]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [test.numberbomb,numberbomb]; arguments []; default message [numberbomb]]; default message [failed convert property value of type 'java.lang.string' required type 'int' property 'numberbomb'; nested exception org.springframework.core.convert.conversionfailedexception: unable convert value "three" type 'java.lang.string' type 'int'; nested exception java.lang.numberformatexception: input string: "three"]
is displaying error messages <form:errors>
wrong way display custom error messages? need add spring config files tell @ messages.properties? spring seems ignoring messages.properties file (which located in web-inf\classes folder)
thanks ideas!
an associate of mine pointed me in right direction. changed messagesource bean in myservlet.xml
from
<bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource"> <property name="basename" value="messages" /> <property name="cacheseconds" value="1" /> </bean>
to
<bean id="messagesource" class="org.springframework.context.support.resourcebundlemessagesource"> <property name="basename" value="messages"/> </bean>
for whatever reason solved problem. associate! :)
Comments
Post a Comment