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.

- how to display an annotation error message beneath a textbox
>

Well, use an Image widget? or a Label widget? call addStyleName on the 
textbox?
You'd still have to manually "map" the error to the appropriate widget 
though.
 

> Could you help me out?
>

The easiest is probably to use the Editor framework:

   - Each Editor has the possibility of doing some validation by itself 
   (implement HasEditorDelegate and then call reportError on the 
   EditorDelegate; if you want to do that only on flush() rather than 
   dynamically as the textbox value changes, then implement ValueAwareEditor)
   - errors passed to EditorDriver#setConstraintViolations are 
   automatically mapped to the corresponding editors, which can implement 
   HasEditorErrors to be notified and display the errors (the way they want); 
   ValueBoxEditorDecorator is one such widget provided out-of-the-box (though 
   not configurable so you'll generally want to build your own)

Your onClick will then:

   1. flush()
   2. check errors from editors
   3. possibly validate using javax.validation, and then call 
   setConstraintViolations to display them (beware that it then clears the one 
   reported by editors themselves, you have to merge both lists of errors)

Using the Editor framework though you'll be editing an existing Person 
object (and/or create an empty Person object specifically to edit it and 
save it later), which also means it has to be mutable.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/gqzz_Dtra-oJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to