A TagConverter
class must implement the following four methods of the atg.droplet.TagConverter
interface:
getName
Returns the name of your converter. This is the name that is used as an argument to the converter attribute in a tag. For example, Dynamo has a converter whose getName
method returns currency
, so you can include a tag like this in your JavaServer Pages:
<dsp:valueof param="myPrice" converter="currency"/>
getTagAttributeDescriptors
Returns the list of attribute arguments that this converter takes. These attributes are listed along with the converter
attribute in your valueof
, input
, or param
tag. These attributes can be marked as optional if they are not required. For example, the currency
converter takes a locale
attribute that is optional. The default behavior if this attribute is missing is to use the locale associated with the current request.
A TagAttributeDescriptor
also can be marked as automatic
, which means that this attribute implies the use of this converter, even if the converter attribute is not specified. For example, the currency
converter defines a currency
attribute that is automatic, so you can use this converter in your page with:
<dsp:valueof param="myPrice" currency/>
You cannot have more than one converter registered with the same automatic attribute. You can replace an existing converter by registering a new one with the same name (after the existing converter has already been registered).
It is legal to define a TagConverter
that takes the same attribute as another TagConverter
as long as it is not ambiguous which converter to use for a given tag. The required
attribute is an automatic attribute for the RequiredTagConverter
. The DateTagConverter
has date
as an automatic attribute and required
as an optional attribute. If you use both date
and required
in the same tag, the DateTagConverter
is used. If you use just required
, the RequiredTagConverter
is used.
convertStringToObject
This method is called in two circumstances:
If you are using an
input
tag, when that form value is submitted, this method is called before thesetX
method of the component is called. YourconvertStringToObject
method must generate theObject
value for use in thesetX
method. It can throw aTagConversionException
if an error occurs during the conversion process.The
convertStringToObject
method for most tag converters returns null if a form field is left empty. If this method returns null, thesetX
method for the corresponding property is not called, and the current value remains unchanged. If, instead, you want your tag converter to set the value to null when a field is left empty, yourconvertStringToObject
method must return the special valueTagConverterManager.SET_AS_NULL
. This value instructs thesetX
method to set the property value to null.This method is also called if you use this converter with a
param
tag when the value of the parameter is defined.
convertObjectToString
This method is called in two situations:
When you use a converter in a
valueof
tag, this method is used to convert theObject
value into aString
value before displaying it.When you use this tag in an
input
tag with abean
attribute and no existingvalue
attribute, this method is called to fill in thevalue
attribute with the current value of the bean property.