public class StringLengthFieldValidator extends FieldValidatorSupport
trim
the
String before performing the length check. If unspecified, the String will be trimmed.
<validators> <!-- Plain Validator Syntax --> <validator type="stringlength"> <param name="fieldName">myPurchaseCode</param> <param name="minLength">10</param> <param name="maxLength">10</param> <param name="trim">true</param> <message>Your purchase code needs to be 10 characters long</message> </validator> <!-- Field Validator Syntax --> <field name="myPurchaseCode"> <field-validator type="stringlength"> <param name="minLength">10</param> <param name="maxLength">10</param> <param name="trim">true</param> <message>Your purchase code needs to be 10 characters long</message> </field-validator> </field> <!-- Field Validator Syntax with expression --> <field name="myPurchaseCode"> <field-validator type="stringlength"> <param name="minLengthExpression">${minLengthValue}</param> <!-- will be evaluated as: Integer getMinLengthValue() --> <param name="maxLengthExpression">${maxLengthValue}</param> <!-- will be evaluated as: Integer getMaxLengthValue() --> <param name="trimExpression">${trimValue}</param> <!-- will be evaluated as: boolean getTrimValue() --> <message>Your purchase code needs to be 10 characters long</message> </field-validator> </field> </validators>
currentValue, fieldName, type
defaultMessage, EMPTY_STRING, messageKey, stack, textProviderFactory
Constructor and Description |
---|
StringLengthFieldValidator() |
Modifier and Type | Method and Description |
---|---|
int |
getMaxLength() |
int |
getMinLength() |
boolean |
isTrim() |
void |
setMaxLength(int maxLength) |
void |
setMaxLengthExpression(String maxLengthExpression) |
void |
setMinLength(int minLength) |
void |
setMinLengthExpression(String minLengthExpression) |
void |
setTrim(boolean trim) |
void |
setTrimExpression(String trimExpression) |
void |
validate(Object object)
The validation implementation must guarantee that setValidatorContext will
be called with a non-null ValidatorContext before validate is called.
|
protected void |
validateValue(Object object,
Object value) |
getCurrentValue, getFieldName, getValidatorType, setFieldName, setValidatorType
addActionError, addFieldError, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext, setValueStack
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack
public void setMaxLength(int maxLength)
public void setMaxLengthExpression(String maxLengthExpression)
public int getMaxLength()
public void setMinLength(int minLength)
public void setMinLengthExpression(String minLengthExpression)
public int getMinLength()
public void setTrim(boolean trim)
public void setTrimExpression(String trimExpression)
public boolean isTrim()
public void validate(Object object) throws ValidationException
Validator
object
- the object to be validated.ValidationException
- is thrown if there is validation error(s).Copyright © 2000–2020 Apache Software Foundation. All rights reserved.