Search code examples
javaspringspring-mvchibernate-validator

Size validation max value is {javax.validation.constraints.Size.message}


I have a field in the student class in the Spring MVC

@Size(min=5,max=30)
    private String studentHobby;

I have put the size validation for it.

and write the following code in the spring-servlet.xml file

 </bean>
<bean id="messageSource" class= "org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename"  value="/WEB-INF/studentmessages"/>
</bean>

studentmessages.properties files is:

Size.student1.studentHobby =pls enter a  value for {0} between {2} and {1} characters

I am getting the value of min field but not getting for max field

pls enter a value for studentHobby between 5 and {javax.validation.constraints.Size.message} characters

can someone let me know what could be the reason for not getting the max value?

Thanks


Solution

  • Don't know how but when i changed the

    studentmessages.properties files as:

    Size.student1.studentHobby = pls enter a  value for {0} between {2} and {4} characters.
    

    It gives me the right message as

    pls enter a value for studentHobby between 5 and 30 characters.