To enable more control over data conversions, the ATG platform provides tag converter classes. Tag converters let you specify how data in forms is interpreted and displayed, and to control when exceptions are thrown. You specify tag converters through special attributes that ATG provides.
For example, your form might have the following field:
<dsp:input type="text" bean="MyBean.age"/>
The tag in this example creates a text input field whose value is used to set the value of the age
property of the MyBean
component on form submission. The ATG platform sets this property by calling setAge()
for the class that is an instance of MyBean
.
Because the age
property has a data type of int
, the user-supplied value must be converted from a string before the call to setAge()
. Thus, if the user enters 26, the text string 26 is converted to int
26. However, if the user enters a string value such as Hello
, the conversion fails and an exception is thrown.
You can specify tag converters in the following DSP tags:
dsp:a
dsp:input
dsp:param
dsp:postfield
dsp:select
dsp:setvalue
dsp:textarea
dsp:valueof
Explicit conversion
You can invoke a tag converter explicitly with the following syntax:
<
tag
-
name
bean="
property-
spec
" converter="
converter
-
name
"
converter
-
name
="
format
">
tag
-
name
property-
spec
identifies the property whose value you wish to convert.converter
specifies the converter to use and the desired output format.
For example:
<dsp:input bean="Seminar.startDate" converter="date" date="M/dd/yyyy"/>
Implicit conversion
A tag can omit the converter
attribute and implicitly invoke a tag converter by specifying only the converter name and format. In the following example, the dsp:input
tag implicitly invokes the date converter:
<dsp:input bean="Seminar.startDate" date="M/dd/yyyy"/>
The following table lists the standard ATG tag converters:
Converter | Inputdatatype | Outputdatatype | Function |
---|---|---|---|
| numeric string | integer, float, etc. | Determines how a credit card number is displayed. |
| numeric string | string | Displays currency in a format appropriate for the locale |
| String | Date | Parses strings into Dates; displays Dates in a variety of formats. |
| Map | Map | Ensures that key-value pairs are parsed correctly for the specified map property. |
| any | any | If field is left empty, corresponding property is set to null |
| numeric string | integer, float, etc. | Displays numeric data-types in a variety of formats |
| any | any | Throws a form exception if the user specifies a null or empty value |
| string | string | Displays a string as formatted HTML text rather than escaped text. |
The following sections discuss tag converters in greater detail.