Displays one or more text values, formatting them based on locale.

Class Name

atg.droplet.Format

Component

/atg/dynamo/droplet/Format

Required Input Parameters

The Format servlet bean typically requires the following input parameters:

The ATG platform uses the format parameter to construct the java.text.MessageFormat object. The value of this parameter is a string that can embed one or more format expressions that use the following syntax:

{arg[,format-type,[format-type]...]}

where arg is a variable that can be formatted, and format-type optionally specifies any format accepted by the java.text.MessageFormat class.

For example:

<dsp:param name="format"
     value="At {when,time} on {when,date}, there was {what} on planet
{where,number,integer}."/>

If arg is a variable—in the previous example, when, what, and where—the servlet bean requires an input parameter of the same name. Given the previous format parameter example, the servlet bean requires three input parameters:

<dsp:param name="when" bean="MyComponent.date"/>
<dsp:param name="what" bean="MyComponent.what"/>
<dsp:param name="where" bean="MyComponent.where"/>

Optional Input Parameters

locale

A dynamic page parameter or static text. The value must correspond to a supported locale format defined in java.util.Locale. If omitted, the ATG platform uses the default locale of the request object.

Output Parameters

message

Renders the servlet bean output, or resultant string that is calculated by processing the supplied input parameters.

Open Parameters

output

Uses a <dsp:valueof> tag to display the final MessageFormatElement with the desired formatting, which is represented by the message page parameter. For example:

<dsp:oparam name="output">
  <dsp:valueof param="message"/>
</dsp:oparam>

Usage Notes

Format makes the functionality of the java.text.MessageFormat class available to JSPs. With it, you can:

This servlet bean lets you format parameters—typically strings—into any format accepted by the java.text.MessageFormat class.

Example

In the following example, the Format servlet bean concatenates two strings. This examples assumes the existence of a MyComponent component with properties firstName and lastName.

<dsp:droplet name="/atg/dynamo/droplet/Format">
   <dsp:param name="format" value="Name: {last},{first}"/>
   <dsp:param bean="/MyComponent.firstName" name="first"/>
   <dsp:param bean="/MyComponent.lastName" name="last"/>
   <dsp:oparam name="output">
     Name: <dsp:valueof param="message"/>
   </dsp:oparam>
 </dsp:droplet>

This code creates two page parameters first and last, and sets the values of each to the corresponding MyComponent property. Format constructs an object and sets each argument to a value in an array, inserting the actual value for each page parameter. Format passes the object equipped with the array to the Messageformat object for formatting. Because this example does not require formatting, the MessageFormat object compiles the final message and saves it to a page parameter called message. The final message might appear as follows:

Name: Dover, Anita