Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Defining Formats

Struts2 supports 1ocalization localization (l10n) aware formatting of dates, times and numbers very easily, utilizing Java's built-in date formatting features.

...

As seen in the Localization chapter, it is quite easy to define hierarchical resource bundles with Struts2, giving the developer the opportunity to define locale dependent message formats. This is the entry point to define the needed date, time and number formats. Your default properties could contain the following generic formats:

...

Code Block
<s:textfield key="orderItem.price" value="%{getText('orderItemformat.pricenumber',{'formatorderItem.number'price})}" />

This maps to the method signature getText( String key, Object[] params ) in ActionSupport.

Using getFormatted() with conversion support

A new method getFormatted was added to ActionSupport (which can be implemented in your base action) to support formatting and conversion errors with I10N.
You can place a code like below

Code Block

<s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />

to get support for I10N and also to support conversion errors.