You can modify the tag converters provided in the Oracle ATG Web Commerce platform; you can also create a custom tag converter in the following steps:
Extend an existing tag converter class or create one that implements interface
atg.droplet.TagConverter
. The new class must implement the following TagConverter methods:Optionally, create attributes for the tag converter through an instance of the
TagAttributeDescriptor
class.Register the new tag converter with the TagConverterManager (
atg.droplet.TagConverterManager
) by callingTagConverterManager.registerTagConverter()
with an instance of the new tag converter’s class. The tag converter must be registered before a JSP can use it. Include the call toregisterTagConverter()
in a class that is initialized during the startup process of your module—that is, is in theInitial
services list.
getName()
Returns the name of the tag converter that is supplied as an argument to the converter
attribute. For example, the getName()
method that is implemented by the tag converter class atg.droplet.CurrencyTagConverter
returns the string currency
. So, a dsp:valueof
tag specifies this tag converter as follows:
<dsp:valueof param="myPrice" converter="currency"/>
getTagAttributeDescriptors()
Returns an array of TagAttributeDescriptors (atg.droplet.TagAttributeDescriptor
). The constructor for a TagAttributeDescriptor is defined as follows:
TagAttributeDescriptor(String pName, String pDescription, boolean pOptional, boolean pAutomatic)
Each TagAttributeDescriptor is defined with an attribute name and description, and two Boolean properties:
Optional
: Specifies whether this attribute is optional or required. For example, Oracle ATG Web Commerce’scurrency
converter takes alocale
attribute whoseOptional
property is set totrue
. If this attribute is omitted, the locale associated with the current request is used. Conversely, theDate
converter’sdate
attribute is marked as required, so allDate
converters must supply a date format.Automatic
: Not supported for custom tag converter, this property specifies whether you can supply the attribute without theconverter
attribute. Only one attribute be marked as automatic; all other attributes must set this property tofalse
.
For example, the tag converter class atg.droplet.Warthog
defines the two
attributes, recommendations
and winddirection
, and sets their Optional and Automatic properties as follows:
public class Warthog implements TagConverter { ... static final String RECS_ATTRIBUTE = "recommendations"; static final String WINDDIR_ATTRIBUTE = " winddirection"; ... private final static TagAttributeDescriptor[] sTagAttributeDescriptors = { new TagAttributeDescriptor(RECS_ATTRIBUTE, "A string for recommendations", false, false), new TagAttributeDescriptor(WINDDIR_ATTRIBUTE, "A string for wind direction", true, false), }
Note: Two constraints apply to custom tag converter attributes:
The
Automatic
property is supported only for Oracle ATG Web Commerce tag converters; DSP tags can only reference custom tag converters through theconverter
attribute.Custom tag converters must reference their attributes through the
converterattributes
attribute. See Using Custom Tag Converters for details.
convertStringToObject()
This method is called when a tag converter is used by one of the following DSP tags:
| On form submission,
|
|
|
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.