Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > text
Added by digi9ten, last edited by Don Brown on Jan 06, 2007  (view change)
Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

Render a I18n text message.

The message must be in a resource bundle with the same name as the action that it is associated with. In practice this means that you should create a properties file in the same package as your Java class with the same name as your class, but with .properties extension.

If the named message is not found, then the body of the tag will be used as default message. If no body is used, then the name of the message will be used.

Parameters

Name

Required

Default

Evaluated

Type

Description

id false true String id for referencing element. For UI and form tags it will be used as HTML id attribute
name true true String Name of resource property to fetch

Examples

Accessing messages from a given bundle (the i18n Shop example bundle in the first example) and using bundle defined through the framework in the second example.</p>
<!-- First Example -->
<s:i18n name="struts.action.test.i18n.Shop">
    <s:text name="main.title"/>
</s:i18n>

<!-- Second Example -->
<s:text name="main.title" />

<!-- Third Examlpe -->
<s:text name="i18n.label.greetings">
   <s:param >Mr Smith</s:param>
</s:text>

Other example

<s:text name="format.money"><s:param name="value" value="myMoneyValue"/></s:text>

where

format.money={0,number,currency}

For more about formatting text, see

  1. http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html
  2. http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html