Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3406332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:36:54+00:00 2026-05-18T05:36:54+00:00

I want to define a set of error messages so that when validation errors

  • 0

I want to define a set of error messages so that when validation errors generate codes, those codes pick up the corresponding error message and print them.

For the sake of learning, and to develop an extendable web app, I’d like to follow the proper i18n path, though I only need to define one (english) set of messages now.

So the locales should all default to english when they don’t find their own resources (which I’m yet to define).

I’ve never used any of the i18n functionality of Java. And the spring docs assume that I have this knowledge.

Could someone just give me a gental nudge in the right direction?

I’ve defined a messageSource in my dispatcher-servlet.xml webapp context. I have a validator which produces a BindingResult object with a rejected field "username", with code "username.taken". I can generate the default message.

Now I just need to get the error message from the errormessages.properties file in my view.

How do I resolve an error code to a message?

<bean id="messageSource"
      class="org.springframework.context.support.ResourceBundleMessageSource">
  <property name="basenames">
    <list>
      <value>errormessages</value>
    </list>
  </property>
</bean>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:36:54+00:00Added an answer on May 18, 2026 at 5:36 am

    It depends on what you want to do with this text. The first possibility is to get the message programmatically:

    @Autowired
    private MessageSource messageSource;
    
    @RenderMapping(params = "render=details")
    public String showDetails (Model model, Locale locale) {
        messageSource.getMessage(<your key goes here>, null, locale);
    }
    

    This way is very uncommon, cause you have to get the message keys form the Errors object by yourself.

    Another more common way is to use the build in view extensions shipped with spring mvc. You didn’t wrote it but I guess your using JSPs. In that case you can simply write something like this in your JSP:

    <!-- showing errors -->
    <div>
        <form:errors path="*" />
    </div>
    
    <!-- showing arbitrary messages -->
    <div>
        <spring:message code="${success.messageKey}"/>
    </div>
    

    For further reading I suggest you http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to define something like this in php : $EL = \n<br />\n;
I want to define some member variable and some code just in Debug Mode,
I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;
I often want to define new 'Exception' classes, but need to have an appropriate
So, I want to define a singleton method for an object, but I want
I want to implement the solution using the pre-processor described here: Reuse define statement
I want to compile a project differently, according to a constant defined by #define,
I defined a record named log . I want to create an mnesia table
I want to call a few static methods of a CPP class defined in
I want to keep the class simple and not defined a constructor so i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.