|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
javax.faces.convert.NumberConverter
org.apache.myfaces.trinidad.convert.NumberConverter
public class NumberConverter
This is an extension of the standard JSF 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)The custom messages can contain placeholders, which will be replaced with values as specified in its corresponding message id.
This NumberConverter is automatically registered under the standard converter ID, and therefore will be used when the <f:convertNumber> tag is used.
| Field Summary | |
|---|---|
static java.lang.String |
CONVERT_CURRENCY_MESSAGE_IDThe message identifier of the FacesMessage to be created if the input value is not a valid number when type is set to 'currency'. |
static java.lang.String |
CONVERT_NUMBER_MESSAGE_IDThe message identifier of the FacesMessage to be created if the input value is not a valid number. |
static java.lang.String |
CONVERT_PATTERN_MESSAGE_IDThe message identifier of the FacesMessage to be created if the input value does not match the specified pattern. |
static java.lang.String |
CONVERT_PERCENT_MESSAGE_IDThe message identifier of the FacesMessage to be created if the input value is not a valid number when type is set to 'percent'. |
static java.lang.String |
CONVERTER_IDThe standard converter id for this converter. |
| Fields inherited from class javax.faces.convert.NumberConverter |
|---|
CURRENCY_ID, NUMBER_ID, PATTERN_ID, PERCENT_ID, STRING_ID |
| Constructor Summary | |
|---|---|
NumberConverter() |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object numberConverter)Compares this NumberConverter with the specified Object for equality. |
java.lang.Object |
getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String value)Performs strict conversion of string to number. |
java.lang.String |
getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value) |
protected javax.faces.application.FacesMessage |
getConvertMessage(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String inputValue, java.lang.Object[] params) |
java.lang.String |
getCurrencyCode() |
java.lang.String |
getCurrencySymbol() |
java.lang.String |
getHintPattern()Return custom hintPattern message. |
java.util.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. |
java.lang.String |
getLocalizedPattern(javax.faces.context.FacesContext context, java.lang.String pattern, java.text.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() |
java.lang.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. |
java.lang.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. |
java.lang.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. |
java.lang.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() |
java.lang.String |
getPattern() |
java.lang.String |
getType() |
javax.faces.el.ValueBinding |
getValueBinding(java.lang.String name)Deprecated. |
javax.el.ValueExpression |
getValueExpression(java.lang.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() |
boolean |
isMaximumFractionDigitsSet()Return true if the maximum fraction digits have been set. |
boolean |
isMaximumIntegerDigitsSet()Return true if the maximum integer digits have been set. |
boolean |
isMinimumFractionDigitsSet()Return true if the minimum fraction digits have been set. |
boolean |
isMinimumIntegerDigitsSet()Return true if the minimum integer digits have been set. |
void |
restoreState(javax.faces.context.FacesContext context, java.lang.Object state) |
java.lang.Object |
saveState(javax.faces.context.FacesContext context) |
void |
setCurrencyCode(java.lang.String currencyCode) |
void |
setCurrencySymbol(java.lang.String currencySymbol) |
void |
setGroupingUsed(boolean groupingUsed) |
void |
setHintPattern(java.lang.String hintPattern)Custom hintPattern message. |
void |
setIntegerOnly(boolean integerOnly) |
void |
setLocale(java.util.Locale locale)Set the Locale to be used when parsing numbers. |
void |
setMaxFractionDigits(int maxFractionDigits) |
void |
setMaxIntegerDigits(int maxIntegerDigits) |
void |
setMessageDetailConvertCurrency(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String pattern) |
void |
setType(java.lang.String type) |
void |
setValueBinding(java.lang.String name, javax.faces.el.ValueBinding binding)Deprecated. |
void |
setValueExpression(java.lang.String name, javax.el.ValueExpression expression)Set the ValueExpression used to calculate the value for the specified attribute if any. |
| Methods inherited from class javax.faces.convert.NumberConverter |
|---|
isTransient, setTransient |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String CONVERTER_ID
The standard converter id for this converter.
public static final java.lang.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 java.lang.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 java.lang.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 java.lang.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.
| Constructor Detail |
|---|
public NumberConverter()
| Method Detail |
|---|
public java.lang.Object getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.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.NumberConverter
public java.lang.String getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.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 performedjava.lang.NullPointerException - if context or component is nulljava.lang.IllegalArgumentException - if the value is not of type other than Number, String. value can be null.
public void restoreState(javax.faces.context.FacesContext context,
java.lang.Object state)
restoreState in interface javax.faces.component.StateHolderrestoreState in class javax.faces.convert.NumberConverterpublic java.lang.Object saveState(javax.faces.context.FacesContext context)
saveState in interface javax.faces.component.StateHoldersaveState in class javax.faces.convert.NumberConverter
public void setValueExpression(java.lang.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 ValueExpressionjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic javax.el.ValueExpression getValueExpression(java.lang.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 ValueExpressionjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converter
public void setValueBinding(java.lang.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 ValueBindingjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic javax.faces.el.ValueBinding getValueBinding(java.lang.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 ValueBindingjava.lang.NullPointerException - if name is nulljava.lang.IllegalArgumentException - if name is not a valid attribute of this converterpublic void setMessageDetailConvertPattern(java.lang.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 java.lang.String getMessageDetailConvertPattern()
FacesMessage when conversion fails for values that does not match the pattern set.setMessageDetailConvertPattern(String)public void setMessageDetailConvertNumber(java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.String hintPattern)
Custom hintPattern message.
Overrides default hint messagehintPattern - Custom hint message.public java.lang.String getHintPattern()
Return custom hintPattern message.
setHintPattern(String)public void setCurrencyCode(java.lang.String currencyCode)
setCurrencyCode in class javax.faces.convert.NumberConverterpublic java.lang.String getCurrencyCode()
getCurrencyCode in class javax.faces.convert.NumberConverterpublic void setCurrencySymbol(java.lang.String currencySymbol)
setCurrencySymbol in class javax.faces.convert.NumberConverterpublic java.lang.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(java.util.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 java.util.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(java.lang.String pattern)
setPattern in class javax.faces.convert.NumberConverterpublic java.lang.String getPattern()
getPattern in class javax.faces.convert.NumberConverter
public java.lang.String getLocalizedPattern(javax.faces.context.FacesContext context,
java.lang.String pattern,
java.text.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(java.lang.String type)
setType in class javax.faces.convert.NumberConverterpublic java.lang.String getType()
getType in class javax.faces.convert.NumberConverterpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object numberConverter)
Compares this NumberConverter with the specified Object for equality.
equals in class java.lang.Object
protected final javax.faces.application.FacesMessage getConvertMessage(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String inputValue,
java.lang.Object[] params)
public boolean isMaximumFractionDigitsSet()
public boolean isMinimumFractionDigitsSet()
public boolean isMaximumIntegerDigitsSet()
public boolean isMinimumIntegerDigitsSet()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.