public class ValidationSupport extends Object implements Validatable
Constructor and Description |
---|
ValidationSupport() |
Modifier and Type | Method and Description |
---|---|
void |
addFailedValidator(Validator validator,
String errorKey)
This method is not to add validators for future processing.
|
<S,T> Converter<S,T> |
converterForClass(String attribute,
Class<S> sourceClass,
Class<T> destinationClass)
Returns converter for specified model attribute, able to convert from sourceClass to destinationClass.
|
<T> Converter<Object,T> |
converterForValue(String attribute,
Object value,
Class<T> destinationClass)
Returns converter for specified model attribute, able to convert value to an instance of destinationClass.
|
void |
convertWith(Converter converter,
String... attributes)
Registers converter for specified model attributes.
|
void |
convertWith(Converter converter,
String attribute)
Registers converter for specified model attribute.
|
void |
dateFormat(DateFormat format,
String... attributes)
Registers date converters (Date -> String -> java.sql.Date) for specified model attributes.
|
void |
dateFormat(String pattern,
String... attributes)
Registers date converters (Date -> String -> java.sql.Date) for specified model attributes.
|
Errors |
errors()
Provides an instance of
Errors object, filled with error messages after validation. |
Errors |
errors(Locale locale)
Provides an instance of localized
Errors object, filled with error messages after validation. |
Object |
get(String attributeName)
Returns a value of an attribute.
|
boolean |
isValid()
Implementation should call {#link validate()} internally.
|
void |
removeValidator(Validator validator) |
void |
timestampFormat(DateFormat format,
String... attributes)
Registers timestamp converters (Date -> String -> java.sql.Timestamp) for specified model attributes.
|
void |
timestampFormat(String pattern,
String... attributes)
Registers timestamp converters (Date -> String -> java.sql.Timestamp) for specified model attributes.
|
void |
validate()
Runs validation.
|
void |
validate(boolean reset)
Runs validation.
|
NumericValidationBuilder |
validateNumericalityOf(String... attributes) |
ValidationBuilder |
validatePresenceOf(String... attributes) |
ValidationBuilder |
validateWith(List<Validator> list) |
ValidationBuilder |
validateWith(Validator validator) |
List<Validator> |
validators() |
public void convertWith(Converter converter, String attribute)
public <S,T> Converter<S,T> converterForClass(String attribute, Class<S> sourceClass, Class<T> destinationClass)
public <T> Converter<Object,T> converterForValue(String attribute, Object value, Class<T> destinationClass)
public ValidationBuilder validateWith(Validator validator)
public ValidationBuilder validateWith(List<Validator> list)
public NumericValidationBuilder validateNumericalityOf(String... attributes)
public ValidationBuilder validatePresenceOf(String... attributes)
public void removeValidator(Validator validator)
public void dateFormat(String pattern, String... attributes)
public void dateFormat(DateFormat format, String... attributes)
public void timestampFormat(String pattern, String... attributes)
public void timestampFormat(DateFormat format, String... attributes)
public void convertWith(Converter converter, String... attributes)
public Object get(String attributeName)
get
in interface Validatable
attributeName
- name of attribute. For a standard class it would be an actual name of a field retrievable
by reflection.public void addFailedValidator(Validator validator, String errorKey)
Validatable
addFailedValidator
in interface Validatable
validator
- validator that failed validation (later to be used to retrieve error message)errorKey
- - generally an attribute name that failed validationpublic boolean isValid()
Validatable
isValid
in interface Validatable
public void validate()
Validatable
validate
in interface Validatable
public void validate(boolean reset)
Validatable
validate
in interface Validatable
reset
- true to reset all previous validation errors.public Errors errors()
Errors
object, filled with error messages after validation.errors
in interface Validatable
Errors
object, filled with error messages after validation.public Errors errors(Locale locale)
Errors
object, filled with error messages after validation.errors
in interface Validatable
locale
- locale.Errors
object, filled with error messages after validation.Copyright © 2020 JavaLite. All rights reserved.