ClassName |
|
---|---|
Component |
|
This servlet bean makes the functionality of the java.text.MessageFormat
class available to JSPs. It provides two functions:
The ability to place the value of one or more page parameters in a string
The ability to format a numeric value as a date, time, currency, or percent format
This servlet bean lets you format parameters, which are usually strings, into any format accepted by the java.text.MessageFormat
class. For more information on MessageFormat
, see the Javadoc provided with your Java software.
Input Parameters
format
The ATG platform uses this parameter to construct the java.text.MessageFormat
object. This parameter specifies the text in full to display, including the items that require formatting and the formatting types. Typically, these items are page parameters supplied between curly braces or strings: the first argument is text or a page parameter that requires formatting and the second is the formatting type. If no formatting is required, exclude the second argument. For a list of acceptable formatting types, see the MessageFormat
section in the manuals that accompany your Java software.
Here is an example:
<dsp:param name="format" value="At {when,time} on {when,date}, there was {what} on planet {where,number,integer}."/>
For currency conversions, the CurrencyFormatter might better suit your needs.
Possible arguments for format
This parameter name references the first value of an argument pair included in the format
parameter. This parameter anchors the format
arguments to page parameter or static text value.
For example, if the format
parameter uses arguments {when,date}
, the parameter might look like this:
<dsp:param="when" bean="MyComponent.date"/>
locale
This parameter takes either a dynamic page parameter or static text as a value. The value must correspond to a supported locale format defined in java.util.Locale
. This parameter is optional; if you exclude it, the ATG platform uses the default locale of the request object.
Output Parameter
message
This parameter renders the servlet bean output, or resultant string that is calculated by processing the supplied input parameters.
Open Parameter
output
This parameter uses a <dsp:valueof>
tag to display the final MessageFormatElement
with the desired formatting, which is represented by the message
page parameter.
<dsp:oparam name="output"> <dsp:valueof param="message"/> </dsp:oparam>
Example
This example demonstrates how to use the Format
servlet bean to concatenate two strings. In order for this example to work, there needs to be a component called MyComponent
with properties firstName,
and lastName
.
<dsp:droplet name="/atg/dynamo/droplet/Format"> <dsp:param name="format" value="{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
, last
) and sets the values of each to the corresponding MyComponent
property. The Format
servlet bean constructs an object and sets each argument to a value in an array, inserting the actual value for each page parameter. The Format
bean 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