Home > front end >  Hibernate Validator showing garbage text in i18n message
Hibernate Validator showing garbage text in i18n message

Time:07-02

It is showing below message in borwser:

નામ à«« થી ૧૨ અકà«àª·àª° સà«àª§à«€ હોવà«àª‚ જોઈàª.

POJO

@Column(name = "name", unique = true, nullable = false, length=45)
@Size(max=12,min=5,message = "{error.name.range}")
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

PROPERTIES- validation_en.properties

error.name.required=Please enter name. error.name.duplicate=Name already exits. error.name.range = Name should be 5-12 characters long.

validation_gu.properties

error.name.required=some other language. error.name.duplicate=some other language. error.name.range = some other language.

XML

   <mvc:annotation-driven validator="validator">
    
    
</mvc:annotation-driven>
 <!-- Localization of hibernate messages during validation!-->
<bean id="validationMessageSource" >
    <property name="basename" value="classpath:validation" />
</bean>

<bean name="validator"  >
    <property name="validationMessageSource">
        <ref bean="validationMessageSource"/>
    </property>
</bean>

JSP:

 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <tr>
                <td width="50%" align="right" style="padding-right:25px">
                    <label for="">
                        <spring:message code="master.user.name" />
                    </label>
                </td>
                <td  width="50%">
                    <form:input path="name" id="name"/> 
                    <form:errors path="name"></form:errors>
                </td>
            </tr>

JAR

hibernate-validator-5.1.1.Final.jar

CodePudding user response:

solved my problem... one hint is enough... Thank you

@Thorbjørn Ravn Andersen

<bean id="validationMessageSource" >
    <property name="basename" value="classpath:validation" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>
  • Related