|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |
javax.faces.convert Class NumberConverter
java.lang.Object javax.faces.convert.NumberConverter
- 所有已实现的接口:
- StateHolder, Converter
public class NumberConverter
- extends Object
- implements Converter, StateHolder
Converter
implementation for java.lang.Number
values.
The getAsObject()
method parses a String into an
java.lang.Double
or java.lang.Long
, according
to the following algorithm:
- If the specified String is null, return
a
null
. Otherwise, trim leading and trailing whitespace before proceeding. - If the specified String - after trimming - has a zero length,
return
null
. - If the
locale
property is not null, use thatLocale
for managing parsing. Otherwise, use theLocale
from theUIViewRoot
. - If a
pattern
has been specified, its syntax must conform the rules specified byjava.text.DecimalFormat
. Such a pattern will be used to parse, and thetype
property will be ignored. - If a
pattern
has not been specified, parsing will be based on thetype
property, which expects a currency, a number, or a percent. The parse pattern for currencies, numbers, and percentages is determined by calling thegetCurrencyInstance()
,getNumberInstance()
, orgetPercentInstance()
method of thejava.text.NumberFormat
class, passing in the selectedLocale
. - If the
integerOnly
property has been set to true, only the integer portion of the String will be parsed. See the JavaDocs for thesetParseIntegerOnly()
method of thejava.text.NumberFormat
class for more information.
The getAsString()
method expects a value of type
java.lang.Number
(or a subclass), and creates a formatted
String according to the following algorithm:
- If the specified value is null, return a zero-length String.
- If the specified value is a String, return it unmodified.
- If the
locale
property is not null, use thatLocale
for managing formatting. Otherwise, use theLocale
from theFacesContext
. - If a
pattern
has been specified, its syntax must conform the rules specified byjava.text.DecimalFormat
. Such a pattern will be used to format, and thetype
property (along with related formatting options described in the next paragraph) will be ignored. - If a
pattern
has not been specified, formatting will be based on thetype
property, which formats the value as a currency, a number, or a percent. The format pattern for currencies, numbers, and percentages is determined by calling the percentages is determined by calling thegetCurrencyInstance()
,getNumberInstance()
, orgetPercentInstance()
method of thejava.text.NumberFormat
class, passing in the selectedLocale
. In addition, the following properties will be applied to the format pattern, if specified:- If the
groupingUsed
property istrue
, thesetGroupingUsed(true)
method on the correspondingNumberFormat
instance will be called. - The minimum and maximum number of digits in the integer and
fractional portions of the result will be configured based on
any values set for the
maxFractionDigits
,maxIntegerDigits
,minFractionDigits
, andminIntegerDigits
properties. - If the type is set to
currency
, it is also possible to configure the currency symbol to be used, using either thecurrencyCode
orcurrencySymbol
properties. If both are set, the value forcurrencyCode
takes precedence on a JDK 1.4 (or later) JVM; otherwise, the value forcurrencySymbol
takes precedence.
- If the
字段摘要 | |
---|---|
static String |
CONVERTER_ID
The standard converter id for this converter. |
static String |
CURRENCY_ID
The message identifier of the FacesMessage to be created if
the conversion to Number fails. |
static String |
NUMBER_ID
The message identifier of the FacesMessage to be created if
the conversion to Number fails. |
static String |
PATTERN_ID
The message identifier of the FacesMessage to be created if
the conversion to Number fails. |
static String |
PERCENT_ID
The message identifier of the FacesMessage to be created if
the conversion to Number fails. |
static String |
STRING_ID
The message identifier of the FacesMessage to be created if
the conversion of the Number value to
String fails. |
构造器摘要 | |
---|---|
NumberConverter()
|
方法摘要 | |
---|---|
Object |
getAsObject(FacesContext context,
UIComponent component,
String value)
Convert the specified string value, which is associated with the specified UIComponent , into a model data object that
is appropriate for being stored during the Apply Request
Values phase of the request processing lifecycle. |
String |
getAsString(FacesContext context,
UIComponent component,
Object value)
Convert the specified model object value, which is associated with the specified UIComponent , into a String that is suitable
for being included in the response generated during the
Render Response phase of the request processing
lifeycle. |
String |
getCurrencyCode()
Return the ISO 4217 currency code used by getAsString()
with a type of currency . |
String |
getCurrencySymbol()
Return the currency symbol used by getAsString()
with a type of currency . |
Locale |
getLocale()
Return the Locale to be used when parsing numbers. |
int |
getMaxFractionDigits()
Return the maximum number of digits getAsString() should
render in the fraction portion of the result. |
int |
getMaxIntegerDigits()
Return the maximum number of digits getAsString() should
render in the integer portion of the result. |
int |
getMinFractionDigits()
Return the minimum number of digits getAsString() should
render in the fraction portion of the result. |
int |
getMinIntegerDigits()
Return the minimum number of digits getAsString() should
render in the integer portion of the result. |
String |
getPattern()
Return the format pattern to be used when formatting and parsing numbers. |
String |
getType()
Return the number type to be used when formatting and parsing numbers. |
boolean |
isGroupingUsed()
Return true if getAsString should include
grouping separators if necessary. |
boolean |
isIntegerOnly()
Return true if only the integer portion of the given
value should be returned from getAsObject() . |
boolean |
isTransient()
If true, the Object implementing this interface must not participate in state saving or restoring. |
void |
restoreState(FacesContext context,
Object state)
Perform any processing required to restore the state from the entries in the state Object. |
Object |
saveState(FacesContext context)
Gets the state of the instance as a Serializable Object. |
void |
setCurrencyCode(String currencyCode)
Set the ISO 4217 currency code used by getAsString()
with a type of currency . |
void |
setCurrencySymbol(String currencySymbol)
Set the currency symbol used by getAsString()
with a type of currency . |
void |
setGroupingUsed(boolean groupingUsed)
Set the flag indicating whether getAsString() should
include grouping separators if necessary. |
void |
setIntegerOnly(boolean integerOnly)
Set to true if only the integer portion of the given
value should be returned from getAsObject() . |
void |
setLocale(Locale locale)
Set the Locale to be used when parsing numbers. |
void |
setMaxFractionDigits(int maxFractionDigits)
Set the maximum number of digits getAsString() should
render in the fraction portion of the result. |
void |
setMaxIntegerDigits(int maxIntegerDigits)
Set the maximum number of digits getAsString() should
render in the integer portion of the result. |
void |
setMinFractionDigits(int minFractionDigits)
Set the minimum number of digits getAsString() should
render in the fraction portion of the result. |
void |
setMinIntegerDigits(int minIntegerDigits)
Set the minimum number of digits getAsString() should
render in the integer portion of the result. |
void |
setPattern(String pattern)
Set the format pattern to be used when formatting and parsing numbers. |
void |
setTransient(boolean transientFlag)
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring. |
void |
setType(String type)
Set the number type to be used when formatting and parsing numbers. |
类方法继承 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
字段详细信息 |
---|
CONVERTER_ID
public static final String CONVERTER_ID
The standard converter id for this converter.
- 另请参见:
- 常量字段
CURRENCY_ID
public static final String CURRENCY_ID
The message identifier of the
FacesMessage
to be created if the conversion toNumber
fails. The message format string for this message may optionally include the following placeholders:{0}
replaced by the unconverted value.{1}
replaced by an example value.{2}
replaced by aString
whose value is the label of the input component that produced this message.
- 另请参见:
- 常量字段
NUMBER_ID
public static final String NUMBER_ID
The message identifier of the
FacesMessage
to be created if the conversion toNumber
fails. The message format string for this message may optionally include the following placeholders:{0}
replaced by the unconverted value.{1}
replaced by an example value.{2}
replaced by aString
whose value is the label of the input component that produced this message.
- 另请参见:
- 常量字段
PATTERN_ID
public static final String PATTERN_ID
The message identifier of the
FacesMessage
to be created if the conversion toNumber
fails. The message format string for this message may optionally include the following placeholders:{0}
replaced by the unconverted value.{1}
replaced by an example value.{2}
replaced by aString
whose value is the label of the input component that produced this message.
- 另请参见:
- 常量字段
PERCENT_ID
public static final String PERCENT_ID
The message identifier of the
FacesMessage
to be created if the conversion toNumber
fails. The message format string for this message may optionally include the following placeholders:{0}
replaced by the unconverted value.{1}
replaced by an example value.{2}
replaced by aString
whose value is the label of the input component that produced this message.
- 另请参见:
- 常量字段
STRING_ID
public static final String STRING_ID
The message identifier of the
FacesMessage
to be created if the conversion of theNumber
value toString
fails. The message format string for this message may optionally include the following placeholders:{0}
relaced by the unconverted value.{1}
replaced by aString
whose value is the label of the input component that produced this message.
- 另请参见:
- 常量字段
构造器详细信息 |
---|
NumberConverter
public NumberConverter()
方法详细信息 |
---|
getCurrencyCode
public String getCurrencyCode()
Return the ISO 4217 currency code used by
getAsString()
with atype
ofcurrency
. If not set, the value used will be based on the formattingLocale
.
setCurrencyCode
public void setCurrencyCode(String currencyCode)
Set the ISO 4217 currency code used by
getAsString()
with atype
ofcurrency
.- 参数:
currencyCode
- The new currency code
getCurrencySymbol
public String getCurrencySymbol()
Return the currency symbol used by
getAsString()
with atype
ofcurrency
. If not set, the value used will be based on the formattingLocale
.
setCurrencySymbol
public void setCurrencySymbol(String currencySymbol)
Set the currency symbol used by
getAsString()
with atype
ofcurrency
.- 参数:
currencySymbol
- The new currency symbol
isGroupingUsed
public boolean isGroupingUsed()
Return
true
ifgetAsString
should include grouping separators if necessary. If not modified, the default value istrue
.
setGroupingUsed
public void setGroupingUsed(boolean groupingUsed)
Set the flag indicating whether
getAsString()
should include grouping separators if necessary.- 参数:
groupingUsed
- The new grouping used flag
isIntegerOnly
public boolean isIntegerOnly()
Return
true
if only the integer portion of the given value should be returned fromgetAsObject()
. If not modified, the default value isfalse
.
setIntegerOnly
public void setIntegerOnly(boolean integerOnly)
Set to
true
if only the integer portion of the given value should be returned fromgetAsObject()
.- 参数:
integerOnly
- The new integer-only flag
getMaxFractionDigits
public int getMaxFractionDigits()
Return the maximum number of digits
getAsString()
should render in the fraction portion of the result.
setMaxFractionDigits
public void setMaxFractionDigits(int maxFractionDigits)
Set the maximum number of digits
getAsString()
should render in the fraction portion of the result. If not set, the number of digits depends on the value being converted.- 参数:
maxFractionDigits
- The new limit
getMaxIntegerDigits
public int getMaxIntegerDigits()
Return the maximum number of digits
getAsString()
should render in the integer portion of the result.
setMaxIntegerDigits
public void setMaxIntegerDigits(int maxIntegerDigits)
Set the maximum number of digits
getAsString()
should render in the integer portion of the result. If not set, the number of digits depends on the value being converted.- 参数:
maxIntegerDigits
- The new limit
getMinFractionDigits
public int getMinFractionDigits()
Return the minimum number of digits
getAsString()
should render in the fraction portion of the result.
setMinFractionDigits
public void setMinFractionDigits(int minFractionDigits)
Set the minimum number of digits
getAsString()
should render in the fraction portion of the result. If not set, the number of digits depends on the value being converted.- 参数:
minFractionDigits
- The new limit
getMinIntegerDigits
public int getMinIntegerDigits()
Return the minimum number of digits
getAsString()
should render in the integer portion of the result.
setMinIntegerDigits
public void setMinIntegerDigits(int minIntegerDigits)
Set the minimum number of digits
getAsString()
should render in the integer portion of the result. If not set, the number of digits depends on the value being converted.- 参数:
minIntegerDigits
- The new limit
getLocale
public Locale getLocale()
Return the
Locale
to be used when parsing numbers. If this value isnull
, theLocale
stored in theUIViewRoot
for the current request will be utilized.
setLocale
public void setLocale(Locale locale)
Set the
Locale
to be used when parsing numbers. If set tonull
, theLocale
stored in theUIViewRoot
for the current request will be utilized.- 参数:
locale
- The newLocale
(ornull
)
getPattern
public String getPattern()
Return the format pattern to be used when formatting and parsing numbers.
setPattern
public void setPattern(String pattern)
Set the format pattern to be used when formatting and parsing numbers. Valid values are those supported by
java.text.DecimalFormat
. An invalid value will cause aConverterException
whengetAsObject()
orgetAsString()
is called.- 参数:
pattern
- The new format pattern
getType
public String getType()
Return the number type to be used when formatting and parsing numbers. If not modified, the default type is
number
.
setType
public void setType(String type)
Set the number type to be used when formatting and parsing numbers. Valid values are
currency
,number
, orpercent
. An invalid value will cause aConverterException
whengetAsObject()
orgetAsString()
is called.- 参数:
type
- The new number style
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, String value)
- Description copied from interface:
Converter
Convert the specified string value, which is associated with the specified
UIComponent
, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.- 规范说明:
getAsObject
in interfaceConverter
- 参数:
context
-FacesContext
for the request being processedcomponent
-UIComponent
with which this model object value is associatedvalue
- String value to be converted (may benull
)- 返回:
null
if the value to convert isnull
, otherwise the result of the conversion- 抛出异常:
ConverterException
- if conversion cannot be successfully performedNullPointerException
- ifcontext
orcomponent
isnull
getAsString
public String getAsString(FacesContext context, UIComponent component, Object value)
- Description copied from interface:
Converter
Convert the specified model object value, which is associated with the specified
UIComponent
, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.- 规范说明:
getAsString
in interfaceConverter
- 参数:
context
-FacesContext
for the request being processedcomponent
-UIComponent
with which this model object value is associatedvalue
- Model object value to be converted (may benull
)- 返回:
- a zero-length String if value is
null
, otherwise the result of the conversion - 抛出异常:
ConverterException
- if conversion cannot be successfully performedNullPointerException
- ifcontext
orcomponent
isnull
saveState
public Object saveState(FacesContext context)
- Description copied from interface:
StateHolder
Gets the state of the instance as a
Serializable
Object.If the class that implements this interface has references to instances that implement StateHolder (such as a
UIComponent
with event handlers, validators, etc.) this method must call theStateHolder.saveState(javax.faces.context.FacesContext)
method on all those instances as well. This method must not save the state of children and facets. That is done via theStateManager
This method must not alter the state of the implementing object. In other words, after executing this code:
Object state = component.saveState(facesContext);
component
should be the same as before executing it.The return from this method must be
Serializable
- 规范说明:
saveState
in interfaceStateHolder
restoreState
public void restoreState(FacesContext context, Object state)
- Description copied from interface:
StateHolder
Perform any processing required to restore the state from the entries in the state Object.
If the class that implements this interface has references to instances that also implement StateHolder (such as a
UIComponent
with event handlers, validators, etc.) this method must call theStateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object)
method on all those instances as well.- 规范说明:
restoreState
in interfaceStateHolder
isTransient
public boolean isTransient()
- Description copied from interface:
StateHolder
If true, the Object implementing this interface must not participate in state saving or restoring.
- 规范说明:
isTransient
in interfaceStateHolder
setTransient
public void setTransient(boolean transientFlag)
- Description copied from interface:
StateHolder
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
- 规范说明:
setTransient
in interfaceStateHolder
- 参数:
transientFlag
- boolean passtrue
if this Object will participate in state saving or restoring, otherwise passfalse
.
|
Java EE 5 SDK 深圳电信培训中心.徐海蛟老师. |
||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |
提交错误或意见
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.