i18n for Validation in Validator Framework

i18n for Validation in Validator Framework

Previous Home Next

 

Validation is aa very powerful feature in struts. i18n in struts is really flexible if set up correctly.when We works with i18n features .i.e differnt rules for a phone number based on country.Internationalization also known as I18N is used for displaying content specific to the locale based on their languages, currencies and formatting conventions.

 
Validation requirements often vary quite a bit based on locale. Each Locale represents a particular choice of country and language , and also a set of formatting assumptions for things like numbers and dates.If you do not specify a locale,it becomes the default locale.We will set of simple Java properties files. Each file contains a key/value pair for each message that you expect your application to present, in the language appropriate for the requesting client.
The naming format for this file is ResourceBundleName.properties. A sample entry in this file would be app.name=Name.
so We can say that every occurrence of the app.name key the Name will be substituted.

Now We could follow step by step of our application...

1. First Step, Create the resource bundles that will contain the key/value pairs used in your application. 
    e.g .  label.user = Naam
             label.password = password
             label.button = Submit

2. Add an application <message-resources /> subelement, naming the wiley. ApplicationResources to the struts-config.xml file.

<message-resources parameter="r4r.co.in.ApplicationResources" />

3. Modify the web.xml file 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
<servlet> 
<servlet-name> action</servlet-name>   
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param> 
<param-name>config</param-name>  
<param-value>/WEB-INF/struts-config.xml</param-value>  
</init-param> 
<init-param> 
<param-name>debug</param-name>  
<param-value>3</param-value> 
</init-param> 
<init-param>   
<param-name>detail</param-name>   
<param-value>3</param-value>
</init-param>   
<init-param>  
<param-name>application</param-name>  
<param-value>AppicationResources_hi</param-value> 
</init-param>  
<init-param>  
<param-name>application</param-name>
<param-value>AppicationResources_en</param-value> 
</init-param>   
<load-on-startup>0</load-on-startup> 
</servlet> 
<servlet-mapping>  
<servlet-name>action</servlet-name>  
<url-pattern>*.do</url-pattern>
</servlet-mapping> 
<welcome-file-list>
<welcome-file>index.jsp</welcome-file> 
</welcome-file-list>
</web-app>

4. Create the index.jsp file and add bean tag library <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> in index.jsp pages.
.


Previous Home Next