DoubleRangeValidator (Java EE 5)

Java EE API


javax.faces.validator Class DoubleRangeValidator

java.lang.Object
  extended by javax.faces.validator.DoubleRangeValidator
All Implemented Interfaces:
EventListener, StateHolder, Validator

public class DoubleRangeValidator
extends Object
implements Validator, StateHolder

Implements: Validator, StateHolder

DoubleRangeValidator 是一个 Validator,它根据指定的最小值和最大值检查相应组件的值。实现以下算法:

  • 如果传递的值为 null,则立即退出。
  • 如果当前组件值不是浮点类型,或者是可以转换成 double 的 String,则抛出包含 TYPE_MESSAGE_ID 消息的 ValidatorException
  • 如果对此 Validator 配置了 maximumminimum 属性,则根据这两个限制检查组件值。如果组件值不在此指定范围内,则抛出包含 #NOT_IN_RANGE_MESSAGE_ID 消息的 ValidatorException
  • 如果对此 Validator 配置了 maximum 属性,则根据此限制检查组件值。如果组件值大于指定的最大值,则抛出包含 MAXIMUM_MESSAGE_ID 消息的 ValidatorException
  • 如果对此 Validator 配置了 minimum 属性,则根据此限制检查组件值。如果组件值小于指定的最小值,则抛出包含 MINIMUM_MESSAGE_ID 消息的 ValidatorException

对于所有导致抛出 ValidatorException 的上述原因,如果有些消息的参数匹配验证器参数,则这些参数的值必须使用转换器 ID javax.faces.Number 在应用程序中注册的 Converter 转换。这使值可以根据当前的 Locale 进行本地化。

英文文档:

DoubleRangeValidator is a Validator that checks the value of the corresponding component against specified minimum and maximum values. The following algorithm is implemented:

  • If the passed value is null, exit immediately.
  • If the current component value is not a floating point type, or a String that is convertible to double, throw a ValidatorException containing a TYPE_MESSAGE_ID message.
  • If both a maximum and minimum property has been configured on this Validator, check the component value against both limits. If the component value is not within this specified range, throw a ValidatorException containing a NOT_IN_RANGE_MESSAGE_ID message.
  • If a maximum property has been configured on this Validator, check the component value against this limit. If the component value is greater than the specified maximum, throw a ValidatorException containing a MAXIMUM_MESSAGE_ID message.
  • If a minimum property has been configured on this Validator, check the component value against this limit. If the component value is less than the specified minimum, throw a ValidatorException containing a MINIMUM_MESSAGE_ID message.

For all of the above cases that cause a ValidatorException to be thrown, if there are parameters to the message that match up with validator parameters, the values of these parameters must be converted using the Converter registered in the application under the converter id javax.faces.Number. This allows the values to be localized according to the current Locale.


Field Summary
static String
static String
static String
static String
static String
 
Constructor Summary
 
Method Summary
 boolean
 double
 double
 int
 boolean
 void
 Object
 void
 void
 void
 void
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

VALIDATOR_ID

public static final String VALIDATOR_ID

The standard converter id for this converter.

See Also:
Constant Field Values


英文文档:

MAXIMUM_MESSAGE_ID

public static final String MAXIMUM_MESSAGE_ID

The message identifier of the FacesMessage to be created if the maximum value check fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the configured maximum value.
  • {1} replaced by a String whose value is the label of the input component that produced this message.

See Also:
Constant Field Values


英文文档:

MINIMUM_MESSAGE_ID

public static final String MINIMUM_MESSAGE_ID

The message identifier of the FacesMessage to be created if the minimum value check fails. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the configured minimum value.
  • {1} replaced by a String whose value is the label of the input component that produced this message.

See Also:
Constant Field Values


英文文档:

NOT_IN_RANGE_MESSAGE_ID

public static final String NOT_IN_RANGE_MESSAGE_ID

The message identifier of the FacesMessage to be created if the maximum or minimum value check fails, and both the maximum and minimum values for this validator have been set. The message format string for this message may optionally include the following placeholders:

  • {0} replaced by the configured minimum value.
  • {1} replaced by the configured maximum value.
  • {2} replaced by a String whose value is the label of the input component that produced this message.

See Also:
Constant Field Values


英文文档:

TYPE_MESSAGE_ID

public static final String TYPE_MESSAGE_ID

The message identifier of the FacesMessage to be created if the current value of this component is not of the correct type. The message format string for this message may optionally include a {0} placeholder that will be replaced by a String whose value is the label of the input component that produced this message.

See Also:
Constant Field Values

Constructor Detail

public DoubleRangeValidator()

构造没有预配置限制的 Validator

英文文档:

DoubleRangeValidator

public DoubleRangeValidator()

Construct a Validator with no preconfigured limits.


public DoubleRangeValidator(double maximum)

构造具有指定预配置限制的 Validator

maximum 允许的最大值
英文文档:

DoubleRangeValidator

public DoubleRangeValidator(double maximum)

Construct a Validator with the specified preconfigured limit.

Parameters:
maximum - Maximum value to allow


public DoubleRangeValidator(double maximum, double minimum)

构造具有指定预配置限制的 Validator

maximum 允许的最大值
minimum 允许的最小值
英文文档:

DoubleRangeValidator

public DoubleRangeValidator(double maximum,
                            double minimum)

Construct a Validator with the specified preconfigured limits.

Parameters:
maximum - Maximum value to allow
minimum - Minimum value to allow

Method Detail

public double getMaximum()

返回此 Validator 强制执行的最大值;如果没有设置,则返回 Double.MAX_VALUE

英文文档:

getMaximum

public double getMaximum()

Return the maximum value to be enforced by this Validator or Double.MAX_VALUE if it has not been set.


public void setMaximum(double maximum)

设置此 Validator 强制执行的最大值。

maximum 新的最大值
英文文档:

setMaximum

public void setMaximum(double maximum)

Set the maximum value to be enforced by this Validator.

Parameters:
maximum - The new maximum value

public double getMinimum()

返回此 Validator 强制执行的最小值;如果没有设置,则返回 Double.MIN_VALUE

英文文档:

getMinimum

public double getMinimum()

Return the minimum value to be enforced by this Validator, or Double.MIN_VALUE if it has not been set.


public void setMinimum(double minimum)

设置此 Validator 强制执行的最小值。

minimum 新的最小值
英文文档:

setMinimum

public void setMinimum(double minimum)

Set the minimum value to be enforced by this Validator.

Parameters:
minimum - The new minimum value

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
ThrowsNullPointerException: NullPointerException 如果 contextcomponentnull
ThrowsValidatorException: NullPointerException 如果验证失败
英文文档:

validate

public void validate(FacesContext context,
                     UIComponent component,
                     Object value)
              throws ValidatorException
Description copied from interface: Validator

Perform the correctness checks implemented by this Validator against the specified UIComponent. If any violations are found, a ValidatorException will be thrown containing the FacesMessage describing the failure.

Specified by:
validate in interface Validator
Parameters:
context - FacesContext for the request we are processing
component - UIComponent we are checking for correctness
value - the value to validate
Throws:
NullPointerException - if context or component is null
ValidatorException - if validation fails

public boolean equals(Object otherObj)
英文文档:

equals

public boolean equals(Object otherObj)
Overrides:
equals in class Object

public int hashCode()
英文文档:

hashCode

public int hashCode()
Overrides:
hashCode in class Object

public Object saveState(FacesContext context)
英文文档:

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 the StateHolder.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 the StateManager

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

Specified by:
saveState in interface StateHolder

public void restoreState(FacesContext context, Object state)
英文文档:

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 the StateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object) method on all those instances as well.

Specified by:
restoreState in interface StateHolder

public boolean isTransient()
英文文档:

isTransient

public boolean isTransient()
Description copied from interface: StateHolder

If true, the Object implementing this interface must not participate in state saving or restoring.

Specified by:
isTransient in interface StateHolder

public void setTransient(boolean transientValue)
英文文档:

setTransient

public void setTransient(boolean transientValue)
Description copied from interface: StateHolder

Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.

Specified by:
setTransient in interface StateHolder
Parameters:
transientValue - boolean pass true if this Object will participate in state saving or restoring, otherwise pass false.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!