Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This tutorial assumes you've completed the Form Validation tutorial and have a working Form_Validation_Struts2_Ant (or Form_Validation_Struts2_Mvn) form_validation project. The example code for this tutorial, Message_Resource_Struts2_Ant or Message_Resource_Struts2_Mvn, is available on Google Code - http://code.google.com/p/struts2-examples/downloads/list. After downloading and unzipping the file, you'll have a folder named Message_Resource_Struts2_Ant (or Message_Resource_Struts2_Mvn). In that folder will be a README.txt file with instructions on now to build and run the example application.message_resource, is available for checkout from the
Struts 2 subversion sandbox at https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examplesImage Added.

Introduction

In this tutorial we'll explore using Struts 2 message resource capabilities (also called resource bundles). Message resources provide a simple way to put text in a view page that is the same through out your application, to create form field labels, and to change text to a specific language based on the user's locale (i18n).

The code provided in this tutorial may be added to the Form Validation example or you can download this tutorial's complete example from Google Code - http://code.google.com/p/struts2-examples/downloads/list as either a Ant build or Maven build project.

Tip

The Struts 2 user mailing list is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.

...

If you're doing this tutorial after completing Form Validation then you can make these changes to that tutorial's example application. Or you can download the finished example application for this tutorial from Google Code - http://code.google.com/p/struts2-examples/downloads/list.

Put the text below in a file named Register.properties in the org.apache.struts.register.action package in src folder (if using the Ant version) or in the src/resources/java folder (if using the Maven version).

Code Block
JAVA
JAVA
titleRegister.properties
personBean.firstName=First name
personBean.lastName=Last name
personBean.age=Age
personBean.email=Email
thankyou=Thank you for registering %{personBean.firstName}.

...

Place the following in a file named package.properties and save that file in package org.apache.struts ( in src folder if using Ant version or in src/main/resources if using Maven version).

Code Block
JAVA
JAVA
titlepackage.properties
greeting=Welcome to The Wonderful World of Struts 2

...