|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.tzavellas.validation.spring.SpringValidator
public class SpringValidator
An adapter of the BeanValidator
to the Spring's Validator
interface.
This class is used to integrate the BeanValidator
with the validation
facilities offered by the Spring Framework and the Spring MVC.
Example code:
import static com.tzavellas.validation.Validators.*; import com.tzavellas.validation.spring.SpringValidator; import org.springframework.validation.Validator; Validator validator = new SpringValidator(domain.Person.class, string("firstName").required(), string("lastName").required(), string("email").required().email(), integer("age").min(18), date("birthdate").past());
Thread safety: This class is thread safe.
BeanValidator
,
Validator
Constructor Summary | |
---|---|
SpringValidator(Class<?> supportedClass)
Create a SpringValidator that supports the specified class and
an empty BeanValidator . |
|
SpringValidator(Class<?> supportedClass,
BeanValidator validator)
Create a SpringValidator that supports the specified class and
delegates to the specified BeanValidator . |
|
SpringValidator(Class<?> supportedClass,
PropertyValidator<?>... propertyValidators)
Create a SpringValidator . |
Method Summary | |
---|---|
void |
addValidator(PropertyValidator<?> v)
Provide a PropertyValidator to be used by the wrapped BeanValidator . |
protected void |
doExtraValidation(Object target,
Errors errors)
This method can be overridden to provide custom validation logic in addition to the BeanValidator that this Validator
delegates to. |
boolean |
isValid(Object target)
A method to test if the specified object is valid. |
boolean |
supports(Class clazz)
|
void |
validate(Object target,
Errors errors)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpringValidator(Class<?> supportedClass)
SpringValidator
that supports the specified class and
an empty BeanValidator
.
For an empty BeanValidator
all objects are valid.
public SpringValidator(Class<?> supportedClass, PropertyValidator<?>... propertyValidators)
SpringValidator
.
supportedClass
- the Class this validator supportspropertyValidators
- the PropertyValidator
s to by used by the wrapped
BeanValidator
public SpringValidator(Class<?> supportedClass, BeanValidator validator)
SpringValidator
that supports the specified class and
delegates to the specified BeanValidator
.
Method Detail |
---|
public void addValidator(PropertyValidator<?> v)
PropertyValidator
to be used by the wrapped BeanValidator
.
v
- the PropertyValidator
public boolean supports(Class clazz)
supports
in interface Validator
public final void validate(Object target, Errors errors)
validate
in interface Validator
public boolean isValid(Object target)
Use this method if you don't care about the errors and the error messages and you just want to see if an object is valid.
target
- the object to validate
protected void doExtraValidation(Object target, Errors errors)
BeanValidator
that this Validator
delegates to.
The default implementation is empty.
target
- the object to validateerrors
- can be used to report any validation errors
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |