Creating a New Amount Format
By default, Canvas Technology platform provides the following three amount formats for the specified countries:
- INDIA- ##,##,###.## (e.g. 23,87,678.08)
- USA - ###,###,###.## (e.g. 455,768,321.90)
- EURO - ###.###.###,## (e.g. 672.762.341,43)
To create a new amount format, perform the following steps:
- For specifying a custom amount format in your application, create an XML file, e.g. cuser-amountformats.xml under resources package for maintaining custom amount formats.
In the StartTaskServlet Java class, add the initializeAmountFormats() method. This method registers the custom Amount formats into Registry by calling registry() of AmountFormatRegistry with source file (cuser-amountformats.xml) as a parameter.
import com.intellectdesign.canvas.pref.amount.AmountFormatRegistry; private void initializeAmountFormats() { try { AmountFormatRegistry amountFormatRegistry = AmountFormatRegistry.getInstance(); amountFormatRegistry.register("cuser-amountformats.xml"); } catch (BaseException e) { LOGGER.error("Unable to start AmountFormatMapRegistry", e); } }
In the cuser-amountformats.xml, a new format has to be defined as follows:
<?xml version="1.0" encoding="UTF-8"?> <canvas-formats type="amount"> <format Id = "SouthAfrica" description = "SouthAfrica Currency Format" negativeSignPosition = "PREFIX" groupSeparator = " " decimalSeparator = "," groupSize = "3" leadingGroupSize = "3" formatter-class = "com.intellectdesign.modelhouse.pref.CustomerAmountFormatter" canOverride = "true" isEnabled = "true" /> <format Id = "INDIA" description = "Indian Currency Format" isEnabled = "false" /> </canvas-formats> <!-- Here, the Indian currency format is overridden by the new definition and it is disabled for displaying in the Combo Box.-->
A format in the cuser-amountformats.xml file is defined as a combination of the following factors:
- Configure the new format with the Id and description attributes that are unique for that particular format (mandatory inputs).
Id - The format is identified by its unique ID.
description - Description for that format that is displayed in the user preferences form. - Configure the groupSeparator, which is the integer value separator (thousands separator). This value varies based on the countries. The default value for the groupSeparator is “,”. If the value is null or if the attribute is not given, then the default value is taken.
For example, groupSeparator=”,”
- Configure the decimalSeparator, which is the decimal value separator. This value varies based on the countries. The default value for the decimalSepartor is “.”. If the value is null or if the attribute is not given, then the default value is taken.
For example, decimalSeparator=”.” - Configure the groupSize, which represents the number of digits to be separated in the ending portion of an integer number. By default, “3” is taken if the value is null or if the attribute is not specified.
For example, (number=3354646873, groupSize=”3”, groupSeparator=',') which is separated as 3354646,873. - Configure the leadingGroupSize, which represents the number of digits to be separated before the ending portion of an integer number.
For example, (number=3354646873, groupSize=”3”, leadingGroupSize=”2”, groupSeparator=',') which is separated as 3,35,46,46,873. By default, “3” is taken if the value is null or if the attribute is not specified. - Configure the negativeSignPosition, which is the value used for supporting negative number formatting. The framework provides the following four formats:
PREFIX - Negative sign is prefixed to the number.
SUFFIX - Negative sign is suffixed to the number.
WRAP - Number is wrapped in the brackets without negative sign. For example, number: -7687.78 is displayed as (7687.78).
NONE - No negative sign is displayed with the number.
By default, PREFIX is taken if the value is null or if the attribute itself is not specified. - Configure the formatter-class for the server-side formatting in case of print and export. If this is provided, the provided formatter class has higher priority than Canvas Framework default formatter class. This is an optional input. By default, the framework takes care of the formatting. This class has to be specified with the full path including the package.
For example, CustomerAmountFormatter class can been specified in the package called com.intellectdesign.modelhouse.pref. The path can be specified as:
formatter-class = "com.intellectdesign.modelhouse.pref.CustomerAmountFormatter"
The formatter-class must implement the IAmountFormatter interface. Inside this class, one method called “formatAmount” must be implemented to format the amount values.
- Configure the client-formatter-class for the client-side formatting in case of form fields and displaying the formatted value in widgets. If this is provided, the provided formatter class has higher priority than Canvas Framework default formatter class. This is an optional input. By default framework takes care of formatting. This class has to be specified with the function name.
For example,
clientamountformat : function() { return { formatAmount:function(){} }; } client-formatter-class = "clientamountformat"
This class must return one method called “formatAmount” that formats the amount values. - Configure the canOverride value as "true" or "false" for any amount format. The default value is false. This attribute indicates whether a definition of the format can be overridden. If it is true, then the definition of the format is overridden with the new format definition.
- Configure the isEnabled value as "true" or "false" for any amount format. The default value is true. If it is true, in user preferences form, the format is displayed in the Combo Box or it is not displayed, but format definition is stored in the registry.