12. JSF Tag Reference
Contents > JSF Tag Reference > JSF Core Tags
10. JSF Core Tag Reference
Contents > JSF Core Tag Reference > f:convertNumber
f:convertNumber |
|
The ConvertNumber tag registers a NumberConverter instance on the component associated with the enclosing tag. A NumberConverter is a JSF converter class that handles the conversion of strings to numbers and vice versa. The convertNumber tag provides a range of options for customizing the appearance of numeric data. It is useful for converting floating-point and integer values from your domain model into a format that is appropriate for your users. The body content of this tag must be empty.
Example:
<h:outputText id="balance" value="#{accountBean.balance}">
<f:convertNumber currencySymbol="$" groupingUsed="#{true}"
maxFractionDigits="2" type="currency"></f:convertNumber>
</h:outputText>
HTML Output
$1,234,567.89
|
Tag Attributes
| currencyCode |
String |
| |
| The currencyCode attribute sets the ISO 4217 currency code to be applied when formatting currencies. |
| currencySymbol |
String |
| |
| The currencySymbol attribute sets the currency symbol to be applied when formatting currencies. |
| groupingUsed |
String |
| |
| The groupingUsed attribute sets a flag specifying whether formatted output will contain grouping separators. Valid expressions must evaluate to a boolean value. The default value for this attribute is true. |
| integerOnly |
String |
| |
| The integerOnly attribute sets a flag specifying whether only the integer part of the value will be formatted. Valid expressions must evaluate to a boolean value. The default value for this attribute is false. |
| locale |
String |
| |
| The locale attribute sets the language, country, and variant for formatting locale-sensitive data such as numbers and dates. If not specified, the Locale returned by FacesContext.getViewRoot().getLocale() will be used. Valid expressions must evaluate to a java.util.Locale. |
| maxFractionDigits |
String |
| |
| The maxFractionDigits attribute sets the maximum number of digits that will be formatted in the fractional portion of the output. Valid expressions must evaluate to an int. |
| maxIntegerDigits |
String |
| |
| The maxIntegerDigits attribute sets the maximum number of digits that will be formatted in the integer portion of the output. Valid expressions must evaluate to an int. |
| minFractionDigits |
String |
| |
| The minFractionDigits attribute sets the minimum number of digits that will be formatted in the fractional portion of the output. Valid expressions must evaluate to an int. |
| minIntegerDigits |
String |
| |
| The minIntegerDigits attribute sets the minimum number of digits that will be formatted in the integer portion of the output. Valid expressions must evaluate to an int. |
| pattern |
String |
| |
| The pattern attribute sets the custom formatting pattern that determines how the number should be formatted. Valid patterns must conform to the syntax rules specified by java.text.DecimalFormat class. See the Java API documentation for more information. |
| type |
String |
| |
| The type attribute specifies how the number string will be formatted. Valid values are "number", "currency", and "percentage". The default value is "number". |
|