Versions Compared

Key

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

...

Instead, the recommended approach is to use Java's built-in date formatting features via use of the webworks:text tag.

Note

While the s:text tag is still very useful to format numbers, date formatting has become a lot easier thanks to the s:date tag.

The sThe webwork:text tag should be used for all i18n values. It will look up the properties file for your action, and from that select the value for the key that you specify. This is best illustrated in an example:

Code Block
<!-- display the number of items in a cart -->
<webwork<s:text name="'cart.items'" value0="cartItems" />

...

Needless to say, this can get a lot more elaborate, with the ability to specify both date and number formatting. Let us consider another example. The goal here is to display a greeting to the user, as well as the date of their last visit.

Code Block
<webwork<s:text name="'last.visit'" value0="userName" value1="lastVisit(userName)" />

...

As you can see, this is a very powerful mechanism and allows you to easily display numbers and dates using any formatting rules that Java allows.

Info
titlevalue0 interface deprecated

The examples above pass in the values as:

Code Block

<s:text name="'text.message'" value0="userName"/>

These values should now (>2.1.7?) be passed as params:

Code Block

<s:text name="'text.message'"> 
    <s:param value="'userName'"/>
</s:text>
Tip
titleSome message format examples

Here are some examples of formatting in the properties file:

Code Block

format.date = {0,date,MM/dd/yy}
format.time = {0,date,MM/dd/yy ha}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,$##0.00}