Yes I know this side. But it still does not tell me:
- how to validate the name before creating the person object (which I'm looking for in terms of numbers like int age; There I'd first like the validator to catch if it's a valid age before creating the person object)
- how to display an annotation error message beneath a textbox
Yes I know this side. But it still does not tell me:
- how to validate the name before creating the person object (which I'm looking for in terms of numbers like int age; There I'd first like the validator to catch if it's a valid age before creating the person object)
- how to display an annotation error message beneath a textbox
Could you help me out?
On Monday, January 7, 2013 3:45:53 PM UTC+1, membersound wrote:Yes I know this side. But it still does not tell me:
- how to validate the name before creating the person object (which I'm looking for in terms of numbers like int age; There I'd first like the validator to catch if it's a valid age before creating the person object)If you want to use the annotations that are on your Person fields, then you have to create a Person object.Technically, I believe you could generate code, the generator reading the annotations and producing code that will be able to validate data before creating the Person object, but there's no such things in GWT proper.That being said, creating a Person object shouldn't be that expensive that you want to avoid it a all costs.
<T> java.util.Set<ConstraintViolation<T>> validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
propertyName
of the class beanType
would the property value be value
ConstraintViolation
objects return null for ConstraintViolation#getRootBean()
and ConstraintViolation#getLeafBean()
beanType
- the bean typepropertyName
- property to validatevalue
- property value to validategroups
- group or list of groups targeted for validation (default to Default
)IllegalArgumentException
- if beanType
is null, if propertyName
null, empty or not a valid object property or if null is passed to the varargs groupsValidationException
- if a non recoverable error happens during the validation processOn Mon, Jan 7, 2013 at 7:42 AM, Thomas Broyer <t.br...@gmail.com> wrote:
On Monday, January 7, 2013 3:45:53 PM UTC+1, membersound wrote:Yes I know this side. But it still does not tell me:
- how to validate the name before creating the person object (which I'm looking for in terms of numbers like int age; There I'd first like the validator to catch if it's a valid age before creating the person object)If you want to use the annotations that are on your Person fields, then you have to create a Person object.Technically, I believe you could generate code, the generator reading the annotations and producing code that will be able to validate data before creating the Person object, but there's no such things in GWT proper.That being said, creating a Person object shouldn't be that expensive that you want to avoid it a all costs.http://docs.oracle.com/javaee/6/api/javax/validation/Validator.html#validateValue(java.lang.Class, java.lang.String, java.lang.Object, java.lang.Class...)
validateValue
<T> java.util.Set<ConstraintViolation<T>> validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
- Validates all constraints placed on the property named
propertyName
of the classbeanType
would the property value bevalue
ConstraintViolation
objects return null forConstraintViolation#getRootBean()
andConstraintViolation#getLeafBean()