public class NumberConverter
extends javax.faces.convert.NumberConverter
NumberConverter
The converter provides all the standard functionality
of the default NumberConverter and is strict while converting to object.
JSF NumberConverter is lenient and 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
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 on trinidad-config.xml
file. If it is not set, then it is defaulted based on the locale. The
value registered in trinidad-config.xml is obtained using
api from RequestContext.
Since Apache Trinidad is compatible only with JDK 1.4 and higher versions,
the currencyCode gets preference over currencySymbol
See RI's NumberConverter for the way in which
currencyCode and currencySymbol gets preference for
different version of JDK.
The detail part of the FacesMessage can be customized.
For each message id there is a corresponding
setter method, which provides for message customization. The customized
messages can contain placeholders as specified in the documentation
for its corresponding message id.
Example: to customize the message for invalid input values, which will result
in conversion error containing CONVERT_NUMBER_MESSAGE_ID, the following,
can be done.
String convertNumberMessageDetail = "{0}" in "{1}" is not valid age.
// Note that, the string can contain placeholders and it will be replaced
// appropriately as specified in the documentation for the corresponding
// message id.
setMessageDetailConvertNumber(convertNumberMessageDetail);
This way user can override detail part of the FacesMessage for
different conversion errors that occur for wrong values, that arise
during conversion.
There is a one to one mapping for message customization which is as given below. The methods used for customizing the detail message associated with each id is given below:
CONVERT_PATTERN_MESSAGE_ID - setMessageDetailConvertPattern(String)
CONVERT_NUMBER_MESSAGE_ID - setMessageDetailConvertNumber(String)
CONVERT_CURRENCY_MESSAGE_ID - setMessageDetailConvertCurrency(String)
CONVERT_PERCENT_MESSAGE_ID - setMessageDetailConvertPercent(String)
This NumberConverter is automatically registered under the standard
converter ID, and therefore will be used when the
<f:convertNumber> tag is used.
| Modifier and Type | Field and Description |
|---|---|
static String |
CONVERT_CURRENCY_MESSAGE_ID
The message identifier of the
FacesMessage
to be created if the input value is not a valid number when type
is set to 'currency'. |
static String |
CONVERT_NUMBER_MESSAGE_ID
The message identifier of the
FacesMessage
to be created if the input value is not a valid number. |
static String |
CONVERT_PATTERN_MESSAGE_ID
The message identifier of the
FacesMessage
to be created if the input value does not match the specified pattern. |
static String |
CONVERT_PERCENT_MESSAGE_ID
The message identifier of the
FacesMessage
to be created if the input value is not a valid number when type
is set to 'percent'. |
static String |
CONVERTER_ID
The standard converter id for this converter.
|
| Constructor and Description |
|---|
NumberConverter() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object numberConverter)
Compares this NumberConverter with the specified Object for equality.
|
Object |
getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
String value)
Performs strict conversion of string to number.
|
String |
getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
Object value) |
protected javax.faces.application.FacesMessage |
getConvertMessage(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
String inputValue,
Object[] params) |
String |
getCurrencyCode() |
String |
getCurrencySymbol() |
String |
getHintPattern()
Return custom hintPattern message.
|
Locale |
getLocale()
Return the
Locale that was set, returns null if it was not set,
while faces RI returns the Locale set on the view root if the locale
is null. |
String |
getLocalizedPattern(javax.faces.context.FacesContext context,
String pattern,
DecimalFormatSymbols dfs)
If
pattern contains the generic currency sign '�', this method will replace it
with the localized currency symbol (if one exists). |
int |
getMaxFractionDigits() |
int |
getMaxIntegerDigits() |
String |
getMessageDetailConvertCurrency()
Return custom detail error message that was set for creating
FacesMessage,
when conversion fails for values, when type is set to
'currency' and pattern is null or not set. |
String |
getMessageDetailConvertNumber()
Return custom detail error message that was set for creating
FacesMessage,
when conversion fails for values, when type is set to 'number' and
pattern is null or not set. |
String |
getMessageDetailConvertPattern()
Custom detail error message that was set for creation of
FacesMessage
when conversion fails for values that does not match the pattern set. |
String |
getMessageDetailConvertPercent()
Return custom detail error message that was set for creating
FacesMessage,
when conversion fails for values, when value cannot be converted to a
number, when type is set to 'percent'
and pattern is null or not set. |
int |
getMinFractionDigits() |
int |
getMinIntegerDigits() |
String |
getPattern() |
String |
getType() |
javax.faces.el.ValueBinding |
getValueBinding(String name)
Deprecated.
|
javax.el.ValueExpression |
getValueExpression(String name)
Return the
ValueExpression used to calculate the value for the
specified attribute name, if any. |
int |
hashCode()
Returns the hash code for this Converter.
|
boolean |
isGroupingUsed() |
boolean |
isIntegerOnly() |
protected boolean |
isMaximumFractionDigitsSet() |
protected boolean |
isMaximumIntegerDigitsSet() |
protected boolean |
isMinimumFractionDigitsSet() |
protected boolean |
isMinimumIntegerDigitsSet() |
void |
restoreState(javax.faces.context.FacesContext context,
Object state) |
Object |
saveState(javax.faces.context.FacesContext context) |
void |
setCurrencyCode(String currencyCode) |
void |
setCurrencySymbol(String currencySymbol) |
void |
setGroupingUsed(boolean groupingUsed) |
void |
setHintPattern(String hintPattern)
Custom hintPattern message.
|
void |
setIntegerOnly(boolean integerOnly) |
void |
setLocale(Locale locale)
Set the
Locale to be used when parsing numbers. |
void |
setMaxFractionDigits(int maxFractionDigits) |
void |
setMaxIntegerDigits(int maxIntegerDigits) |
void |
setMessageDetailConvertCurrency(String convertCurrencyMessageDetail)
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. |
void |
setMessageDetailConvertNumber(String convertNumberMessageDetail)
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. |
void |
setMessageDetailConvertPattern(String convertPatternMessageDetail)
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. |
void |
setMessageDetailConvertPercent(String convertPercentMessageDetail)
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. |
void |
setMinFractionDigits(int minFractionDigits) |
void |
setMinIntegerDigits(int minIntegerDigits) |
void |
setPattern(String pattern) |
void |
setType(String type) |
void |
setValueBinding(String name,
javax.faces.el.ValueBinding binding)
Deprecated.
|
void |
setValueExpression(String name,
javax.el.ValueExpression expression)
Set the
ValueExpression used to calculate the value for the
specified attribute if any. |
public static final String CONVERTER_ID
The standard converter id for this converter.
public static final String CONVERT_PATTERN_MESSAGE_ID
The message identifier of the FacesMessage
to be created if the input value does not match the specified pattern.
The message format string for this message may optionally
include {0}, {1} and {4}
placeholders, which will be replaced with the input value,
label associated with the component and the pattern respectively.
public static final String CONVERT_NUMBER_MESSAGE_ID
The message identifier of the FacesMessage
to be created if the input value is not a valid number. The message format
string for this message may optionally include {0} and
{1} placeholders, which will be replaced with
the input value and label associated with the component
respectively.
public static final String CONVERT_CURRENCY_MESSAGE_ID
The message identifier of the FacesMessage
to be created if the input value is not a valid number when type
is set to 'currency'. The message format
string for this message may optionally include {0} and
{1} placeholders, which will be replaced with
the input value and label associated with the component
respectively.
public static final String CONVERT_PERCENT_MESSAGE_ID
The message identifier of the FacesMessage
to be created if the input value is not a valid number when type
is set to 'percent'. The message format
string for this message may optionally include {0} and
{1} placeholders, which will be replaced with
the input value and label associated with the component
respectively.
public Object getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String value)
22.22.22
and values of the form 22ABC, 22%ABC will result in
ConverterException.getAsObject in interface javax.faces.convert.ConvertergetAsObject in class javax.faces.convert.NumberConverterpublic String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
getAsString in interface javax.faces.convert.ConvertergetAsString in class javax.faces.convert.NumberConvertercontext - FacesContext for the request being processedcomponent - UIComponent with which this model object
value is associated.value - Model object value to be converted (may be null)null,
if the passed value is a String, it's returned unchanged,
otherwise String representation for the number object based on the
attributes set.javax.faces.convert.ConverterException - if conversion cannot be successfully
performedNullPointerException - if context or
component is nullIllegalArgumentException - if the value is not of
type other than Number, String.
value can be null.public void restoreState(javax.faces.context.FacesContext context,
Object state)
restoreState in interface javax.faces.component.StateHolderrestoreState in class javax.faces.convert.NumberConverterpublic Object saveState(javax.faces.context.FacesContext context)
saveState in interface javax.faces.component.StateHoldersaveState in class javax.faces.convert.NumberConverterpublic void setValueExpression(String name, javax.el.ValueExpression expression)
Set the ValueExpression used to calculate the value for the
specified attribute if any.
name - Name of the attribute for which to set a ValueExpressionexpression - The ValueExpression to set, or null
to remove any currently set ValueExpressionNullPointerException - if name
is nullIllegalArgumentException - if name is not a valid
attribute of this converterpublic javax.el.ValueExpression getValueExpression(String name)
Return the ValueExpression used to calculate the value for the
specified attribute name, if any.
name - Name of the attribute or property for which to retrieve a
ValueExpressionNullPointerException - if name
is nullIllegalArgumentException - if name is not a valid
attribute of this converterpublic void setValueBinding(String name, javax.faces.el.ValueBinding binding)
Set the ValueBinding used to calculate the value for the
specified attribute if any.
name - Name of the attribute for which to set a ValueBindingbinding - The ValueBinding to set, or null
to remove any currently set ValueBindingNullPointerException - if name
is nullIllegalArgumentException - if name is not a valid
attribute of this converterpublic javax.faces.el.ValueBinding getValueBinding(String name)
Return the ValueBinding used to calculate the value for the
specified attribute name, if any.
name - Name of the attribute or property for which to retrieve a
ValueBindingNullPointerException - if name
is nullIllegalArgumentException - if name is not a valid
attribute of this converterpublic void setMessageDetailConvertPattern(String convertPatternMessageDetail)
FacesMessage,
message, when value cannot be converted to a number,
based on the pattern set.
Overrides detail message identified by message id CONVERT_PATTERN_MESSAGE_IDconvertPatternMessageDetail - Custom error message.public String getMessageDetailConvertPattern()
FacesMessage
when conversion fails for values that does not match the pattern set.setMessageDetailConvertPattern(String)public void setMessageDetailConvertNumber(String convertNumberMessageDetail)
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.
CONVERT_NUMBER_MESSAGE_IDconvertNumberMessageDetail - custom error message.public String getMessageDetailConvertNumber()
Return custom detail error message that was set for creating FacesMessage,
when conversion fails for values, when type is set to 'number' and
pattern is null or not set.
setMessageDetailConvertNumber(String)public void setMessageDetailConvertCurrency(String convertCurrencyMessageDetail)
FacesMessage, when value
cannot be converted to a number, when type is set to
'currency' and pattern is null or not set.
Overrides detail message identified by message id CONVERT_CURRENCY_MESSAGE_ID.convertCurrencyMessageDetail - custom error message.public String getMessageDetailConvertCurrency()
Return custom detail error message that was set for creating FacesMessage,
when conversion fails for values, when type is set to
'currency' and pattern is null or not set.
setMessageDetailConvertCurrency(String)public void setMessageDetailConvertPercent(String convertPercentMessageDetail)
FacesMessage, when value cannot be converted to a
number, when type is set to 'percent' and
pattern is null or not set.
Overrides detail message identified by message id CONVERT_PERCENT_MESSAGE_IDconvertPercentMessageDetail - custom error message.public String getMessageDetailConvertPercent()
Return custom detail error message that was set for creating FacesMessage,
when conversion fails for values, when value cannot be converted to a
number, when type is set to 'percent'
and pattern is null or not set.
setMessageDetailConvertPercent(String)public void setHintPattern(String hintPattern)
Custom hintPattern message.
Overrides default hint messagehintPattern - Custom hint message.public String getHintPattern()
Return custom hintPattern message.
setHintPattern(String)public void setCurrencyCode(String currencyCode)
setCurrencyCode in class javax.faces.convert.NumberConverterpublic String getCurrencyCode()
getCurrencyCode in class javax.faces.convert.NumberConverterpublic void setCurrencySymbol(String currencySymbol)
setCurrencySymbol in class javax.faces.convert.NumberConverterpublic String getCurrencySymbol()
getCurrencySymbol in class javax.faces.convert.NumberConverterpublic void setGroupingUsed(boolean groupingUsed)
setGroupingUsed in class javax.faces.convert.NumberConverterpublic boolean isGroupingUsed()
isGroupingUsed in class javax.faces.convert.NumberConverterpublic void setIntegerOnly(boolean integerOnly)
setIntegerOnly in class javax.faces.convert.NumberConverterpublic boolean isIntegerOnly()
isIntegerOnly in class javax.faces.convert.NumberConverterpublic void setLocale(Locale locale)
Set the Locale to be used when parsing numbers.
If set to null, the Locale stored in the
UIViewRoot for the current request
will be utilized.
setLocale in class javax.faces.convert.NumberConverterlocale - The new Locale (or null)public Locale getLocale()
Return the Locale that was set, returns null if it was not set,
while faces RI returns the Locale set on the view root if the locale
is null.
If this value is null, the Locale stored
in the UIViewRoot for the current request
will be utilized during parsing.
getLocale in class javax.faces.convert.NumberConverterpublic void setMaxFractionDigits(int maxFractionDigits)
setMaxFractionDigits in class javax.faces.convert.NumberConverterpublic int getMaxFractionDigits()
getMaxFractionDigits in class javax.faces.convert.NumberConverterpublic void setMaxIntegerDigits(int maxIntegerDigits)
setMaxIntegerDigits in class javax.faces.convert.NumberConverterpublic int getMaxIntegerDigits()
getMaxIntegerDigits in class javax.faces.convert.NumberConverterpublic void setMinFractionDigits(int minFractionDigits)
setMinFractionDigits in class javax.faces.convert.NumberConverterpublic int getMinFractionDigits()
getMinFractionDigits in class javax.faces.convert.NumberConverterpublic void setMinIntegerDigits(int minIntegerDigits)
setMinIntegerDigits in class javax.faces.convert.NumberConverterpublic int getMinIntegerDigits()
getMinIntegerDigits in class javax.faces.convert.NumberConverterpublic void setPattern(String pattern)
setPattern in class javax.faces.convert.NumberConverterpublic String getPattern()
getPattern in class javax.faces.convert.NumberConverterpublic String getLocalizedPattern(javax.faces.context.FacesContext context, String pattern, DecimalFormatSymbols dfs)
pattern contains the generic currency sign '�', this method will replace it
with the localized currency symbol (if one exists).context - the FacesContextpattern - the pattern to be localizeddfs - the DecimalFormatSymbols; if null, will be constructed from the contextpublic void setType(String type)
setType in class javax.faces.convert.NumberConverterpublic String getType()
getType in class javax.faces.convert.NumberConverterpublic int hashCode()
public boolean equals(Object numberConverter)
Compares this NumberConverter with the specified Object for equality.
protected final javax.faces.application.FacesMessage getConvertMessage(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
String inputValue,
Object[] params)
protected boolean isMaximumFractionDigitsSet()
protected boolean isMinimumFractionDigitsSet()
protected boolean isMaximumIntegerDigitsSet()
protected boolean isMinimumIntegerDigitsSet()
Copyright © 2001-2016 The Apache Software Foundation. All Rights Reserved.