Summary
Tag Name: | tr:convertNumber> |
Type: | org.apache.myfaces.trinidad.Number |
This is an extension of the standard JSF javax.faces.convert.NumberConverter The converter provides all the standard functionality of the default NumberConverter and is strict while converting to object.
JSF javax.faces.convert.NumberConverter will convert values like 22.22.2 or 22ABC to valid Number 22.22 and 22 respectively. Here it would result in a conversion failure and would throw a ConverterException.
If number grouping separator, decimal separator is configured in trinidad-config.xml file, it will be used during call to getAsObject() and getAsString() for parsing and formatting. If it has not been set, number grouping separator, decimal separator is defaulted based on the locale.
If currencyCode is set on the converter then it will be used. Else uses the currencyCode set in trinidad-config.xml file. If it is not set in the configuration file then it is defaulted based on the locale.
Since Apache MyFaces Trinidad is compatible with JDK 1.4 and higher versions, the currencyCode gets preference over currencySymbol. See JSF's javax.faces.convert.NumberConverter for the way in which currencyCode and currencySymbol gets preference for different version of JDK.
This converter is automatically registered under the standard converter ID, and therefore will be used when the <f:convertNumber> tag is used.
Further more information see javadoc for org.apache.myfaces.trinidad.converter.NumberConverter
Code Example(s)
<tr:inputText id="mdf5" value="0.75" label="Score"> <tr:convertNumber type='percent' locale="en-US" /> </tr:inputText>
Attributes
Name | Type | Supports EL? | Description |
---|---|---|---|
currencyCode | String | Yes | The ISO 4217 currency code, applied only when formatting currencies. Currency code can also be set for the entire application in trinidad-config.xml file. If currency code is not set on the converter, and if set on trinidad-config.xml configuration file it will be used by calling RequestContext().getCurrenctInstance().getCurrencyCode(). This currency code will be used during call to getAsString() for formatting, provided type is set to 'currency'. |
currencySymbol | String | Yes | Currency symbol, is applied only when formatting currencies. If currency code is set then symbol will be ignored. |
disabled | boolean | Yes |
Default Value: false Whether the converter should be disabled, default to false. |
groupingUsed | boolean | Yes |
Default Value: true Flag specifying whether formatted output will contain grouping separators. Default value is true. |
integerOnly | boolean | Yes |
Default Value: false Flag specifying whether only the integer part of the value will be formatted and parsed. Default value is false. |
locale | java.util.Locale | Yes | Locale whose predefined styles for numbers are used during formatting and parsing. If not specified, the Locale returned by FacesContext.getViewRoot().getLocale() will be used. |
maxFractionDigits | int | Yes | Maximum number of digits that will be formatted in the fractional portion of the output. |
maxIntegerDigits | int | Yes | Maximum number of digits that will be formatted in the integer portion of the output. |
messageDetailConvertCurrency | String | Yes |
Custom error message to be used, for creating detail part of the FacesMessage, when value cannot be converted to a number, when type is set to 'currency' and pattern is null or not set. Parameters:
|
messageDetailConvertNumber | String | Yes |
Custom error message to be used, for creating detail part of the FacesMessage, when value cannot be converted to a number, when type is set to 'number' and pattern is null or not set. Parameters:
|
messageDetailConvertPattern | String | Yes |
Custom error message to be used, for creating detail part of the FacesMessage message, when value cannot be converted to a number, based on the pattern set. Parameters:
|
messageDetailConvertPercent | String | Yes |
Custom error message to be used, for creating detail part of the FacesMessage, when value cannot be converted to a number, when type is set to 'percent' and pattern is null or not set. Parameters:
|
minFractionDigits | int | Yes | Minimum number of digits that will be formatted in the fractional portion of the output. |
minIntegerDigits | int | Yes | Minimum number of digits that will be formatted in the integer portion of the output. |
negativePrefix | String | Yes | Specifies the negative prefix, to be applied only when formatting negative numbers. Negative prefix specified through this attribute will override any negative prefix implied using the pattern attribute |
negativeSuffix | String | Yes | Specifies the negative suffix, to be applied only when formatting negative numbers. Negative suffix specified through this attribute will override any negative suffix implied using the pattern attribute |
pattern | String | Yes | Custom formatting pattern which determins how the number string should be formatted and parsed. |
roundingMode | java.math.RoundingMode | Yes | Sets the default RoundingMode for the converter. If unset, uses JDK default (usually RoundingMode.HALF_EVEN). |
type | String | Yes |
Default Value: number Specifies how the number string will be formatted and parsed. Valid values are "number", "currency", and "percent". Default value is "number". |