|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
javax.faces.validator Class LengthValidator
java.lang.Objectjavax.faces.validator.LengthValidator
- All Implemented Interfaces:
- EventListener, StateHolder, Validator
public class LengthValidator
- extends Object
- implements Validator, StateHolder
LengthValidator 是一个 Validator,它检查关联组件值的 String 表示形式中的字符数。实现以下算法:
- 如有必要,可调用其
toString方法将传递的值转换为 String。 - 如果对此
Validator配置了maximum属性,则根据此限制检查转换的 String。如果 String 长度大于指定的最大值,则抛出包含 MAXIMUM_MESSAGE_ID 消息的ValidatorException。 - 如果对此
Validator配置了minimum属性,则根据此限制检查转换的 String。如果 String 长度小于指定的最小值,则抛出包含 MINIMUM_MESSAGE_ID 消息的ValidatorException。
对于所有导致抛出 ValidatorException 的上述原因,如果有些消息的参数匹配验证器参数,则这些参数的值必须使用转换器 ID javax.faces.Number 在应用程序中注册的 Converter 转换。这使值可以根据当前的 Locale 进行本地化。
LengthValidator is a Validator that checks
the number of characters in the String representation of the value of the
associated component. The following algorithm is implemented:
- Convert the passed value to a String, if necessary, by calling its
toString()method. - If a
maximumproperty has been configured on thisValidator, check the length of the converted String against this limit. If the String length is larger than the specified maximum, throw aValidatorExceptioncontaining a a MAXIMUM_MESSAGE_ID message. - If a
minimumproperty has been configured on thisValidator, check the length of the converted String against this limit. If the String length is less than the specified minimum, throw aValidatorExceptioncontaining a 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 |
MAXIMUM_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the maximum length check fails. |
static String |
MINIMUM_MESSAGE_ID
The message identifier of the FacesMessage to be created if
the minimum length check fails. |
static String |
VALIDATOR_ID
The standard validator id for this validator. |
| Fields inherited from interface javax.faces.validator.Validator |
|---|
NOT_IN_RANGE_MESSAGE_ID |
| Constructor Summary | |
|---|---|
LengthValidator()
Construct a Validator with no preconfigured limits. |
|
LengthValidator(int maximum)
Construct a Validator with the specified preconfigured
limit. |
|
LengthValidator(int maximum,
int minimum)
Construct a Validator with the specified preconfigured
limits. |
|
| Method Summary | |
|---|---|
boolean |
equals(Object otherObj)
|
int |
getMaximum()
Return the maximum length to be enforced by this Validator, or 0 if the maximum has not been
set. |
int |
getMinimum()
Return the minimum length to be enforced by this Validator, or 0 if the minimum has not been
set. |
int |
hashCode()
|
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 |
setMaximum(int maximum)
Set the maximum length to be enforced by this Validator. |
void |
setMinimum(int minimum)
Set the minimum length to be enforced by this Validator. |
void |
setTransient(boolean transientValue)
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring. |
void |
validate(FacesContext context,
UIComponent component,
Object value)
Perform the correctness checks implemented by this Validator against the specified UIComponent. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
英文文档:
VALIDATOR_ID
public static final String VALIDATOR_ID
The standard validator id for this validator.
- See Also:
- Constant Field Values
英文文档:
MAXIMUM_MESSAGE_ID
public static final String MAXIMUM_MESSAGE_ID
The message identifier of the
FacesMessageto be created if the maximum length check fails. The message format string for this message may optionally include the following placeholders:{0}replaced by the configured maximum length.{1}replaced by aStringwhose 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
FacesMessageto be created if the minimum length check fails. The message format string for this message may optionally include the following placeholders:{0}replaced by the configured minimum length.{1}replaced by aStringwhose value is the label of the input component that produced this message.
- See Also:
- Constant Field Values
| Constructor Detail |
|---|
public
LengthValidator()
构造没有预配置限制的 Validator。
LengthValidator
public LengthValidator()
Construct a
Validatorwith no preconfigured limits.
public
LengthValidator(int maximum)
构造具有指定预配置限制的 Validator。
| maximum | 允许的最大值 |
LengthValidator
public LengthValidator(int maximum)
Construct a
Validatorwith the specified preconfigured limit.- Parameters:
maximum- Maximum value to allow
public
LengthValidator(int maximum, int minimum)
构造具有指定预配置限制的 Validator。
| maximum | 允许的最大值 |
| minimum | 允许的最小值 |
LengthValidator
public LengthValidator(int maximum,
int minimum)
Construct a
Validatorwith the specified preconfigured limits.- Parameters:
maximum- Maximum value to allowminimum- Minimum value to allow
| Method Detail |
|---|
public int
getMaximum()
返回此 Validator 强制执行的最大长度;如果没有设置最大值,则返回 0。
getMaximum
public int getMaximum()
Return the maximum length to be enforced by this
Validator, or0if the maximum has not been set.
public void
setMaximum(int maximum)
设置此 Validator 强制执行的最大长度。
| maximum | 新的最大值 |
setMaximum
public void setMaximum(int maximum)
Set the maximum length to be enforced by this
Validator.- Parameters:
maximum- The new maximum value
public int
getMinimum()
返回此 Validator 强制执行的最小长度;如果没有设置最小值,则返回 0。
getMinimum
public int getMinimum()
Return the minimum length to be enforced by this
Validator, or0if the minimum has not been set.
public void
setMinimum(int minimum)
设置此 Validator 强制执行的最小长度。
| minimum | 新的最小值 |
setMinimum
public void setMinimum(int minimum)
Set the minimum length to be enforced by this
Validator.- Parameters:
minimum- The new minimum value
public void
validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
| Throws | NullPointerException:
NullPointerException
如果 context 或 component 为 null |
| Throws | ValidatorException: 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
Validatoragainst the specifiedUIComponent. If any violations are found, aValidatorExceptionwill be thrown containing theFacesMessagedescribing the failure.- Parameters:
context- FacesContext for the request we are processingcomponent- UIComponent we are checking for correctnessvalue- the value to validate- Throws:
NullPointerException- ifcontextorcomponentisnullValidatorException- if validation fails
public boolean
equals(Object otherObj)
英文文档:
equals
public boolean equals(Object otherObj)
public int
hashCode()
英文文档:
hashCode
public int hashCode()
public Object
saveState(FacesContext context)
英文文档:
saveState
public Object saveState(FacesContext context)
- Description copied from interface:
StateHolder Gets the state of the instance as a
SerializableObject.If the class that implements this interface has references to instances that implement StateHolder (such as a
UIComponentwith 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 theStateManagerThis method must not alter the state of the implementing object. In other words, after executing this code:
Object state = component.saveState(facesContext);
componentshould be the same as before executing it.The return from this method must be
Serializable- Specified by:
saveStatein interfaceStateHolder
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
UIComponentwith event handlers, validators, etc.) this method must call theStateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object)method on all those instances as well.- Specified by:
restoreStatein interfaceStateHolder
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:
isTransientin interfaceStateHolder
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:
setTransientin interfaceStateHolder
- Parameters:
transientValue- boolean passtrueif this Object will participate in state saving or restoring, otherwise passfalse.
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!
javax.faces.validator.LengthValidator