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

  • SEARCH
  • Home
  • 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 8987049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:41:51+00:00 2026-06-15T21:41:51+00:00

I have a simple bean defining user credentials on signup registration form model: public

  • 0

I have a simple bean defining user credentials on signup registration form model:

public class UserCreds {
    @Length(min=1, max=50)
    @NotEmpty
    private String username;

    @Email
    private String email;

    @NotEmpty
    @Length(min=1, max=50)
    private String password;

    private String passwordConfirm;

    ... only obvious getters and setters below this line ...
}

I pass it’s instance under “userCreds” model attribute, so i have a following localization bundle:

NotEmpty.userCreds.username=Username is required
NotEmpty.userCreds.password=Passsword is required
Length.userCreds.username=Username length must be between {2} and {1} symbols
Length.userCreds.password=Password length must be between {2} and {1} symbols
Email.userCreds.email=Ill-formed e-mail address

And it works!

The problem here: i don’t want use this cryptic {N} placeholders, which may change their places occasionally (in bundle above ‘max’ is binded to {1} and ‘min’ is binded to {2}, which is at least non-obvious positioning) i wish to use full names of annotaions, as in

Length.userCreds.username=Username length must be between {min} and {max} symbols

(which is not working – when i try it – am getting java.lang.IllegalArgumentException: can't parse argument number min exception)

As i could when define message in code (the following example also works):

@Length(min=1, max=50, message = "Username length must be between {min} and {max} symbols")
@NotEmpty
private String username;

But when i define it in code i loose my ability to localize the message for different languages.

What do?

UPDATE 1


After a few hours of poking around debugger in my IDE i found that using the following class:

public class BakaMessageSource extends ReloadableResourceBundleMessageSource {

    @Override
    protected MessageFormat resolveCode(String code, Locale locale) {
        /* original implementation *
        for (String basename : basenames) {
            List<String> filenames = calculateAllFilenames(basename, locale);
            for (String filename : filenames) {
                PropertiesHolder propHolder = getProperties(filename);
                MessageFormat result = propHolder.getMessageFormat(code, locale);
                if (result != null) {
                    return result;
                }
            }
        }
        */
        return null;
    }
}

With the following spring-servlet.xml declaration:

<bean id="messageSource" class="org.eientei.radiorandom.framework.crutchy.BakaMessageSource"
          p:defaultEncoding="UTF-8"
          p:alwaysUseMessageFormat="false"
            >
        <property name="basenames">
            <list>
                <!-- my application-specific localization bundles -->
                <value>classpath:messages/root/errorMessages</value>
                <value>classpath:messages/root/langMessages</value>
                <value>classpath:messages/user/signupMessages</value>
            </list>
        </property>
    </bean>

instead of original ReloadableResourceBundleMessageSource actually helps to get localized messages with named parameters.

But i guess swapping classes around at that point is not a proper solution. Which one would be?

UPDATE 2

I am such an idiot. I forgot in-code message and thought it got interpolated properly. Geez.
So, alphabetical ordering… guess i can’t ask for more.

  • 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-06-15T21:41:52+00:00Added an answer on June 15, 2026 at 9:41 pm

    I think that the actual order is alphabetical (“max” is lesser than “min”) starting from Spring 3.0.4.

    From SPR-6730 discussion (Juergen Hoeller post)

    For the first option, Spring-managed field error arguments include the
    actual constraint annotation attributes in alphabetical order now. So
    for @Size(min=1,max=5), it’ll include the field name as {0} , the max
    value as {1} , and the min value as {2}

    See https://jira.springsource.org/browse/SPR-6730

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

Sidebar

Related Questions

Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
I have a simple bean, i.e.: public class MyBean { private boolean selected; private
I have a simple class like this, import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; public class Form
I have a simple bean with enum field public class TestBean{ @Pattern(regexp = A|B)
Say I have the following simple java bean: class MyBean { private Date startDate;
I have a simple JSF+RichFaces form with some fields and obviously a backing bean
I have simple form with SpringMVC, I want retrieve my already had bean by
I have a simple form and a pretty simple bean that listens to an
I have a simple standalone application with spring (Main class + bean class). It
I have the following XML configuration: <bean id=bean1 class=Simple/> <bean id=bean2 class=Simple/> <bean id=tasks

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.