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.

@@@version@@@, @@@date@@@org.apache.velocity.tools.struts.MessageTool$textGabriel Sidler<tool> <key>text</key> <scope>request</scope> <class>org.apache.velocity.tools.struts.MessageTool</class> </tool>

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) Message key. The (non-default) message-resources bundle that holds the message. 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). The localized message for the specified key. Returns null if no message exists for the key passed. 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) Message key. The (non-default) message-resources bundle that holds the message. true if a message string for the specified message key exists for the user's locale. false otherwise. $text.exists("title")