Advertisement :
   Log In    OR    Register  
  Topics :  
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 : 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...


Written By : ISHTEK
Title :
Struts2 Tiles I18N Example
Description : with code explained article
More...


Written By : Amit
Title :
Struts2 Tag Library Example
Description : Tutorial
More...

Tags/Keywords : Struts, Struts2 Tutorial, Struts 2 Example, Struts2
Author : ISHTEK
Date (Year/Month/Date): 2009-03-20 Struts2-Tiles-I18N-Example code discussed

Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this 
as it is without appropriate evaluation to their, so to say, 
specific programming context.

This page intends only to provide bit and piece of known ways  for
doing some sort of example and may not be fit for any other purpose.

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).


	
Are you interested in solving a very interesting Technology Stack while Playing this Game          

Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
38,10
Enter bigger number from above :*
Home >>> Struts Struts 2 Example Tutorial >>> Struts2 Tiles I18N Example >>> with code explained article
Visitor/User referred related external URL:
(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 *:
9,31
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed materials, 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.

By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or 
downloading any materials, you agree to and are bound by the terms of use 
described in this page and Usage Terms and Conditions. 
If you do not agree to all of 
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this 
website in any manner. If you are using the website on behalf of your 
employer, you represent that you are authorized to accept these Terms of Use 
on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any 
of these information, please refer original content/documentation from respective sources. 
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.