Advertisement
Home > Struts Struts 2 Example Tutorial > Struts2 Tiles I18N Example > with code explained articlePlease log in to add or reply to any matter<- requires login or
RMI Example

Home > Struts Struts 2 Example Tutorial > Struts2 Tiles I18N Example > with code explained article
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : Amit
Title :
Struts2 example tutorial
Description : My First example using Apache Struts2
More...


Written By : ISHTEK
Title :
Struts2
Description : Tags such as IF Iterator Tags
More...


Written By : guddu
Title :
Struts Eclipse MVC
Description : Step by step demonstration
More...


Written By : Girish
Title :
Struts Tiles I18N Example
Description : Code with Sample Action
More...


Written By : ISHTEK
Title :
Struts2 questions
Description : open for discussion
More...


Written By : ISHTEK
Title :
Struts2 Tiles Example
Description : with Code and article
More...

Struts 2 Tutorial, Struts 2 Example
Author : ISHTEK
Date (Year/Month/Date): 2009-03-20 Struts2-Tiles-I18N-Example code discussed
References:
Struts2 Tag Library Example
/Struts-Struts-2-Example-Tutorial/Struts2-example-tutorial/My-First-example-using-Apache-Struts2
/Struts-Struts-2-Example-Tutorial/Struts-Tiles-I18N-Example/Code-with-Sample-Action
/Struts-Struts-2-Example-Tutorial/Struts2-Tiles-I18N-Example/with-code-explained-article
/Struts-Struts-2-Example-Tutorial/Struts2-Tiles-Example/with-Code-and-article

Using Apache Struts 2.x with Tiles and having i18n capability
demonstration with the help of a sample or example WAR web
application:

This example tries to show in a simple and straight forward
way of presenting an example web application having MVC and Tiles
frameworks for rapid environment staging for a web application
with Internationalization or I18N capability.

Note: this example is for learning purpose only and neither to be used
as some proven idea nor treat it as a recommendation to use from this site.
Reader should take appropriate time to evaluate all aspects of
application development criterias before making any final decision.

Following are the key components/parts of this example:
Software environment used for this example :

1. JDK 5.0
2. Tomcat 5.5.x
3. Eclipse Genymede
4. Apache Struts 2.1.6  (example Web application should have
   following JAR files in WEB-INF\lib folder)
   
   (Note: This example is not tested with any
     other version of Apache Struts )

I have to write following files for this example:

1. MyExample\WEB-INF\classes\struts.xml
2. MyExample\WEB-INF\tiles.xml
3. MyExample\WEB-INF\tiles_hi_IN.xml (Tiles file for the Hindi language
                                      country code as IN)
4. MyExample\WEB-INF\web.xml
5. MyExample\WEB-INF\classes\sample\MyExample.java
6. MyExample\good.jsp
7. MyExample\bad.jsp
8. MyExample\visitor.jsp
9. MyExample\index.html


Advertisement
Please refer earlier example for details related to all the files required for setting up Struts2 with Tiles (Basic example) In order to make this example Struts2 web application work with I18N capability for Tiles, mostly we have to change the Action class to make it SessionAware or retrieve HttpSession from the HttpServletRequest object, and then set the LOCALE attribute as the Locale with Language as "hi" and Country code as "IN". So the changed Action class is as follows: MyExample.java package sample; /** * This code is provided "AS IS" without any guaranty * Use of this code only for educational and learning * purpose only. * Author: Amit * Contact : usingframeworks@gmail.com * Date: 16-Feb-2009 */ import org.apache.struts2.ServletActionContext; import org.apache.struts2.interceptor.SessionAware; import org.apache.struts2.dispatcher.mapper.ActionMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.util.Locale; import java.util.Map; /** * This is the Action POJO class */ public class MyExample implements SessionAware { HttpSession session; public void setSession(Map map) { System.out.println(map); this.session = (HttpSession)map.get(0); } public String execute() throws Exception { //This code is just to show ways to retrieve Http request and HttpSession HttpServletRequest request = ServletActionContext.getRequest(); Locale locale = new Locale("hi", "IN"); if(session == null) this.session = request.getSession(true); session.setAttribute("org.apache.tiles.LOCALE", locale); String tmp = (String)request.getParameter("txtUserName"); if(tmp.contains("good")) return "good"; if(tmp.contains("bad")) return "bad"; else return "visitor"; } } By setting "org.apache.tiles.LOCALE"session attribute as Locale("hi","IN") we can use the Locale specific tiles file as "tiles_hi_IN.xml" The corresponding tiles file is as folows: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> <tiles-definitions> <definition name="good-sample" template="/good.jsp"> <put-attribute name="message" value="Bahut Aacha"/> </definition> </tiles-definitions> So the good.jsp file when called from the struts result typed as "tiles" good.jsp <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t1" %> <font color="green"><b><t1:getAsString name="message"/></b></font> This page will print on browser as "Bahut Aacha" (meaning in Hindi as "Very nice")
Advertisement
Author of this article/writeup has expressed his/her willingness
to help or guide users with any technical difficulties he/she faces while working with the example code environment setting up, running and resolving any such exception raised during compile or at runtime. You may ask for any technical doubt or seek technical help related to this article by using following form to reach for technical help from the Author for FREE. This article's Author shall be reading your request and responding within reasonable time (no resolution timeframe defined as such).
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
35,14
Enter bigger number from above :*
Home > Struts Struts 2 Example Tutorial > Struts2 Tiles I18N Example > with code explained article
Visitor/User submitted related resources:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
21,11
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
This List is generated as on 2009-07-12 (YYYY-MM-DD)
#Discuss-these : questions-and-answer : Interview-Questions-on-Java #Some-facts-about-MVC-Framework-and-Struts : MVC-Struts : Struts-Struts-2-Example-Tutorial #My-First-example-using-Apache-Struts2 : Struts2-example-tutorial : Struts-Struts-2-Example-Tutorial This article discusses steps of creating a Struts2 based example web application With lots of easy to understand explaination and source code for reference. #Tags-such-as-IF-Iterator-Tags : Struts2 : Struts-Struts-2-Example-Tutorial #Step-by-step-demonstration : Struts-Eclipse-MVC : Struts-Struts-2-Example-Tutorial #Code-with-Sample-Action : Struts-Tiles-I18N-Example : Struts-Struts-2-Example-Tutorial #open-for-discussion : Struts2-questions : Struts-Struts-2-Example-Tutorial #with-Code-and-article : Struts2-Tiles-Example : Struts-Struts-2-Example-Tutorial #with-code-explained-article : Struts2-Tiles-I18N-Example : Struts-Struts-2-Example-Tutorial #Tutorial : Struts2-Tag-Library-Example : Struts-Struts-2-Example-Tutorial #Code-and-Tutorial : Struts2-Tags-Example : Struts-Struts-2-Example-Tutorial #Step-By-Step-Code : Radio-Tag-Example : Struts-Struts-2-Example-Tutorial #Struts-2-Code : Struts2-Validation-Example : Struts-Struts-2-Example-Tutorial #Struts-2-Example-with-Code : Struts2-HibernateSession-Plugin : Struts-Struts-2-Example-Tutorial
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed matterials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.