Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Struts Struts 2 Example Tutorial >>> Struts Tiles I18N Example >>> Code with Sample Action
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 :
MVC Struts
Description : Some facts about MVC Framework and Struts
More...


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

Tags/Keywords : Struts, Struts2 Tutorial, Struts 2 Example, Struts2
Author : Girish
Date (Year/Month/Date): 2009-03-17 Struts-Tiles-I18N-Example

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

Following are the key components/parts of this example:

  • Action class as SampleAction
  • extends org.apache.struts.action.Action and overriding execute method as follows: public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("In SampleAction"); return mapping.findForward("success"); } This action class "SampleAction" is mapped in struts-config.xml file as follows: <action path="/main" type="in.i2w.ui.SampleAction" scope="request" name="SampleForm" > <forward name="success" path="/welcome.do"/> <forward name="failure" path="/signup.do"/> </action>
    Advertisement :
    So this shows that if the URL has the path as /main.do, then SampleAction will be called, and after printing out "In SampleAction", flow moves to /welcome.do as the action path, so corresponding action definition in struts-config.xml file as follows: <action path="/welcome" type="in.i2w.ui.SampleWelcomeAction" scope="request" name="SampleWelcomeForm" > <forward name="success" path="sampleWelcomeSuccess"/> <forward name="failure" path="sampleWelcomeFailure"/> </action> This shows that action with path as "/welcome" will be called with execution of execute method in SampleWelcomeAction action class.
  • Action class SampleWelcomeAction
  • execute method as: public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ System.out.println("in SampleWelcomeAction"); HttpSession session = request.getSession(false); Locale locale = new Locale("hi","IN"); session.setAttribute(ComponentConstants.LOCALE_KEY, locale); return mapping.findForward("success"); } This SampleWelcomeAction class execute method will do system out println "in SampleWelcomeAction" on server console/log depending on the server setting. Then appropriate Locale is to be set in HttpSession, with a key as org.apache.struts.taglib.tiles.ComponentConstants.LOCALE_KEY. and then forwarding control to "success" (as defined in struts-config.xml file). Corresponding section in struts-config.xml file has the path to "sampleWelcomeSuccess" as shown above. <forward name="success" path="sampleWelcomeSuccess"/> As this path is a String and now having "/" and ".do" at begin and end of this String value, so it is referring to the Tiles definition in appropriate Tiles definition file with Locale having language as "hi" and country as "IN", so the final tiles definition file looked/searched for by tiles framework is "tiles-defs_hi_IN.xml" instead of the default one "tiles-defs.xml". The default tiles definition file "tiles-defs.xml" file is mentioned in struts-config.xml as : <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <set-property property="moduleAware" value="true" /> </plug-in> There is no need to mention the Locale specific Tiles definition files to be mentioned in struts-config XML file. And there is no need to define any of the text in Message Resource properties flat file. web.xml file should have appropriate Action Servlet configuration as: <servlet-name>sample-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> ..... ..... <servlet-mapping> <servlet-name>sample-action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> Appropriate Tiles definition file "tiles-defs_hi_IN.xml" will be described as : <tiles-definitions> <definition name="sampleWelcomeSuccess" path="/front/welcome.jsp"> <put name="title" value="Subha Pravata" /> </definition> </tiles-definitions> So /front/welcome.jsp file will be referring to the values put in the tiles definition file like: title=Subha Pravata. For you reference, welcome.jsp file would look something like: <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> <html> <head> <title><tiles:getAsString name="title"/></title> </head> <body> </body> </html> So thiw welcome.jsp file show the Title bar as "Subha Pravata", and in absense of the Locale specific tiles file "tiles-defs_hi_IN.xml", the default tiles definition file "tiles-defs.xml" will be read, and the title bar of the welcome.jsp will be print as "Welcome User", as the default tiles definition is as follows: <tiles-definitions> <definition name="sampleWelcomeSuccess" path="/front/welcome.jsp"> <put name="title" value="Welcome User" /> </definition> </tiles-definitions> I have not provided complete source as it is, but in bits and pieces for our interested visitor/reader to create this example and see it running as desired. Your feedback and comments will be a great help to the Author for improvement (if any).
    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).
    
    
    	

    Commented By ->
    Amit
    Nicely explained, but can you provide complete source code
    for this example, so that I would like to run and see it myself.
    
    Thanks in advance, buddy :)

    Commented By ->
    Guddu
    Can I use unicode in Tiles definition XML file as well?
    

    Commented By ->
    Guddu
    Recently I came across a nice web site with lots of insides for
    Internationalization and Localization using Struts and JSF.
    
    Hope this can be useful to readers of this Page:
    Link as follows:
    
    http://www.objectsource.com/j2eechapters/Ch19-I18N_and_L10N.htm

    Commented By ->
    Vane
    I did something like that, but the
    ModuleConfigVerifier throws an ERROR when 
    verifying Forward Configuration, because of the
    missing '/' as firs character on path property.
    
    I think this verification shouldn't be thrown in 
    this case, because we're referencing to a tile 
    instead an URI.
    
    Do you know how can I do to skip this particular 
    verification?
    
    Thanks in advance...
    

    Commented By ->
    Girish
    Hi Vane,
    
    can you show or suggest some pointers towards the present
    example, so as to be able to understand your question properly?
    
    Thanks,
    Girish
    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: *
    24,33
    Enter bigger number from above :*
    Home >>> Struts Struts 2 Example Tutorial >>> Struts Tiles I18N Example >>> Code with Sample Action
    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 *:
    3,21
    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.