The Jakarta Project < Velocity Tools - Struts >

Velocity Tools

VelocityStruts

VelocityStruts Tools

Other Subprojects

MessageTool Reference Documentation
       

The MessageTool is used to render internationalized message strings. Source of the strings are the message resource bundles of the Struts framework. The following methods operate on these message resources.

Class
 org.apache.velocity.tools.struts.MessageTool
Name
 $text (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>text</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
Author(s)
  Gabriel Sidler
Method Overview
get() Looks up and returns the localized message for the specified key.
exists() Checks if a message string for a specified message key exists for the user's locale.
get()
       

Looks up and returns the localized message for the specified key.

TextKey get(String key)

String get(String key, String bundle)

String get(String key, Object args[])

String get(String key, String bundle, Object args[])

String get(String key, List args)

String get(String key, String bundle, List args)

Parameters
key
Message key.
bundle
The (non-default) message-resources bundle that holds the message.
args
Replacement parameters for this message. Typically an array of Strings or a List of Strings (but any Object with a reasonable toString() method can be used).
Returns
The localized message for the specified key. Returns null if no message exists for the key passed.
See Also
Struts user's guide on Internationalized Messages.

The user's locale is consulted to determine the language of the message. The third, fourth, fifth and sixth signatures take a list of up to five replacement parameters. The third and fourth signatures are provided for compatibility with existing applications. The fifth and sixth signatures are more Velocity friendly.

Assuming that the message resource files contain the following messages:

title=Welcome to Velocity for Struts
test=This message has five replacement parameters: {0}, {1}, {2}, {3}, {4}
label.one=foobar
label.two=woogie!

then the following Velocity script:

$text.title
$text.get('test', ['bear', 'wolf', 'tiger'])
$text.label.one
$text.label.two

produces this output:

Welcome to Velocity for Struts
Welcome to Velocity for Struts
This message has five replacement parameters: bear, wolf, tiger, {3}, {4}
foobar
woogie!

exists()
       

Checks if a message string for a specified message key exists for the user's locale.

boolean exists(String key)

boolean exists(String key, String bundle)

Parameters
key
Message key.
bundle
The (non-default) message-resources bundle that holds the message.
Returns
true if a message string for the specified message key exists for the user's locale. false otherwise.
$text.exists("title")


Copyright © 1999-2003, Apache Software Foundation