|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.binding.validation.support.HibernateRulesValidator
public class HibernateRulesValidator
Validator which uses the ClassValidator
of Hibernate to discover
InvalidValue
. These are then translated to ValidationMessage
s
and added to the ValidationResults
as usual.
Usage in a ValidatingFormModel
where SomeClass
has
annotations for Hibernate Validator:
formModel.setValidator(new HibernateRulesValidator(formModel, SomeClass.class));
This can be used in combination with other Validator
s as well by
creating a CompositeRichValidator
:
HibernateRulesValidator hibernateRulesValidator = new HibernateRulesValidator(getFormModel(), SomeClass.class); hibernateRulesValidator.addIgnoredHibernateProperty("ignoredProperty"); RulesValidator rulesValidator = new RulesValidator(getFormModel(), myRulesSource); getFormModel().setValidator(new CompositeRichValidator(rulesValidator, hibernateRulesValidator));
Note that we're adding one property to the HibernateRulesValidator
that will be ignored. This property will only be checked at your back-end by
Hibernate. The RulesValidator
adds additional rules that are only
used at the front-end or/and may contain the equivalent of the
AssertTrue
or AssertFalse
methods on SomeClass
.
Constructor Summary | |
---|---|
HibernateRulesValidator(ValidatingFormModel formModel,
Class clazz)
Creates a new HibernateRulesValidator without ignoring any properties. |
|
HibernateRulesValidator(ValidatingFormModel formModel,
Class clazz,
Set<String> ignoredHibernateProperties)
Creates a new HibernateRulesValidator with additionally a set of properties that should not be validated. |
Method Summary | |
---|---|
void |
addIgnoredHibernateProperty(String propertyName)
Add a property for the Hibernate validator to ignore. |
protected void |
addInvalidValues(org.hibernate.validator.InvalidValue[] invalidValues)
Add all InvalidValue s to the ValidationResults . |
void |
clearMessages()
Clear the current validationMessages and the errors. |
protected org.hibernate.validator.InvalidValue[] |
doHibernateValidate(Object object,
String property)
Validates the object through Hibernate Validator |
void |
removeIgnoredHibernateProperty(String propertyName)
Remove a property for the Hibernate validator to ignore. |
String |
resolveObjectName(String objectName)
resolves a field name to a user friendly display name |
protected ValidationMessage |
translateMessage(org.hibernate.validator.InvalidValue invalidValue)
Translate a single InvalidValue to a ValidationMessage . |
ValidationResults |
validate(Object object)
Validates the provided object. |
ValidationResults |
validate(Object object,
String propertyName)
Validates the given property of the provided object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HibernateRulesValidator(ValidatingFormModel formModel, Class clazz)
formModel
- The ValidatingFormModel
on which validation
needs to occurclazz
- The class of the object this validator needs to checkpublic HibernateRulesValidator(ValidatingFormModel formModel, Class clazz, Set<String> ignoredHibernateProperties)
formModel
- The ValidatingFormModel
on which validation
needs to occurclazz
- The class of the object this validator needs to checkignoredHibernateProperties
- properties that should not be checked
though areMethod Detail |
---|
public ValidationResults validate(Object object)
validate
in interface Validator
object
- the object to validate
public ValidationResults validate(Object object, String propertyName)
validate
in interface RichValidator
object
- the object to validate (may be an implementation ofpropertyName
- the name of the only property that has changed since the
last call to validate.
protected void addInvalidValues(org.hibernate.validator.InvalidValue[] invalidValues)
InvalidValue
s to the ValidationResults
.
protected ValidationMessage translateMessage(org.hibernate.validator.InvalidValue invalidValue)
InvalidValue
to a ValidationMessage
.
protected org.hibernate.validator.InvalidValue[] doHibernateValidate(Object object, String property)
object
- The object that needs to be validatedproperty
- The properties that needs to be validated
InvalidValue
, containing all validation
errorspublic void clearMessages()
validate(Object, String)
public void addIgnoredHibernateProperty(String propertyName)
propertyName
- Name of the property to ignore. Cannot be null.public void removeIgnoredHibernateProperty(String propertyName)
propertyName
- Name of the property to be removed. Cannot be null.public String resolveObjectName(String objectName)
resolveObjectName
in interface ObjectNameResolver
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |