File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Using resource bundle for validation messages in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Using resource bundle for validation messages in Spring" Watch "Using resource bundle for validation messages in Spring" New topic

Using resource bundle for validation messages in Spring

jas preet
Ranch Hand

Joined: Mar 31, 2010
Posts: 78

What i am trying to do is
1. putting up the messages file in WEB-INF/i18/ and trying to validate the messages on login.

The dispatcher-servlet.xml contains

the valdation class

below is the error console
org.springframework.context.NoSuchMessageException: No message found under code 'username.required' for locale 'en_US'.
at org.springframework.web.servlet.tags.form.ErrorsTag.exposeAttributes(
at org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.writeTagContent(
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(
at org.apache.jsp.WEB_002dINF.jsp.home_jsp._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.ApplicationDispatcher.invoke(
at org.apache.catalina.core.ApplicationDispatcher.processRequest(
at org.apache.catalina.core.ApplicationDispatcher.doForward(
at org.apache.catalina.core.ApplicationDispatcher.forward(
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(
at org.springframework.web.servlet.view.AbstractView.render(
at org.springframework.web.servlet.DispatcherServlet.render(
at org.springframework.web.servlet.DispatcherServlet.doDispatch(
at org.springframework.web.servlet.DispatcherServlet.doService(
at org.springframework.web.servlet.FrameworkServlet.processRequest(
at org.springframework.web.servlet.FrameworkServlet.doGet(

But when i put my properties file under src folder and change my dispatcher-servelet as
<bean id="messageSource" class="">
<property name="basenames" value="validationMessages_en">

all seems to work fine.

What may be the problem if i use i18n and put my properties file under this folder

Thanks Jaspreet ----- Nothing is permanent
Sean Clark

Joined: Jul 15, 2009
Posts: 377


If in doubt check the javadocs:

Set an array of basenames, each following ResourceBundle conventions: essentially, a fully-qualified classpath location. If it doesn't contain a package qualifier (such as org.mypackage), it will be resolved from the classpath root.

Which is why when you put it on the classpath root it is found.

Hope this helps.


I love this place!
I agree. Here's the link:
subject: Using resource bundle for validation messages in Spring
It's not a secret anymore!