ATG provides tag converter classes that let you explicitly control how form data is converted on input and displayed on output, and determine when exceptions are thrown. Certain DSP tags such as dsp:input
and dsp:valueof
can specify these tag converters.
For example, the ATG installation provides a CreditCard
tag converter, which lets you control how to mask a portion of the String that represents a credit card number. The following dsp:valueof
tag specifies the CreditCard
tag converter and two of its attributes, maskcharacter
and numcharsunmasked
, which specify to use # as the mask character and to expose the credit card number’s last six digits, respectively:
<dsp:valueof param="paymentGroup.ccNum"
converter="CreditCard" maskcharacter="#" numcharsunmasked="6"
No number available
</valueof>
The following DSP tags can specify tag converters:
dsp:a
dsp:input
dsp:param
dsp:postfield
dsp:select
dsp:setvalue
dsp:textarea
dsp:valueof
Tag Converter Syntax
You can invoke a tag converter explicitly with the following syntax:
<
dsp-tag
converter="
converter
-
name
"
[
attribute-
name
="
value
"
]...
/>
dsp-tag
converter
specifies the name of the converter.attribute-name
optionally specifies an attribute defined in the tag converter. You can specify multiple attributes for a given tag converter.
For example, the following dsp:input
tag specifies the tag converter Date
and supplies its date
attribute . The date
attribute is set to a format supported by java.text.SimpleDateFormat
:
<dsp:input bean="Seminar.startDate" converter="Date" date="M/dd/yyyy"/>
Implicit Converters
A DSP tag can omit the converter
attribute and implicitly invoke a tag converter by specifying an attribute that the tag converter defines as automatic. Each tag converter can define one automatic attribute. In the following example, the dsp:input
tag implicitly invokes the date converter through its automatic attribute date
:
<dsp:input bean="Seminar.startDate" date="M/dd/yyyy"/>
Standard Tag Converters
The following table lists tag converters that are provided with the ATG platform. These are discussed in detail later in this chapter.
Converter | Input data type | Output data type | Function |
---|---|---|---|
numeric string | integer, float, etc. | Determines how a credit card number is displayed. | |
currency | 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. |
Custom Tag Converters
If your installation includes custom tag converters, a DSP tag can invoke these as follows:
<
dsp-tag
converter="
converter
-
name
" converterattributes=
attr-list
/>
attr-list
is a list of semi-colon-delimited attributes that are defined by the tag converter, and their values. The convertattributes
attribute allows use of attributes that are unknown to the DSPJSP
tag library (http://www.atg.com/taglibs/daf/dspjspTaglib1_0
).
For example, given a custom tag converter Warthog
that defines two attributes, recommendations
and winddirection
, a dsp:input
tag can specify this tag converter as follows:
<dsp:input type="text"
bean="NuclearOrderFormHandler.address1"
converter="warthog"
converterattributes="recommendations=splunge;winddirection=west" />
For information about defining tag converters, see the ATG Platform Programming Guide.