Re: GWT Client side validation

223 views
Skip to first unread message

Thomas Broyer

unread,
Jul 15, 2012, 2:03:53 PM7/15/12
to google-we...@googlegroups.com

On Friday, July 13, 2012 11:12:08 PM UTC+2, David Lee wrote:
I have been researching practices and frameworks for client side GWT Validation.
The GWT Validation Library using JSR 303 doesn't seem what I am looking for.
The problem with this and similar validation is that you need to put data into a class and then validate it.
I want to validate data while its still in GWT Widgets and make visual indications on the GUI when there are problems.
I have run across several implementations that do this but wondering if I am missing something obvious.
I'm using GWT 2.5 (rc1) and it seems so unbelievable that it doesnt directly support a type of form validation without having to write it all from scratch,
but that is what I am discovering.

There are 2 ways to do validation, all based on the Editor framework:
  • editors can do the validation themselves (they'll implement HasEditorDelegate and call reportError on the EditorDelegate, generally on getValue() –for a LeafValueEditor– or flush() –for a ValueAwareEditor–)
  • validation can be done on the edited value (flush() the widgets into the object, then use JSR303 validation) and then violations passed back to the EditorDriver with setConstraintViolations for display
To display errors, editors implement HasEditorErrors.

There are only 2 built-in classes that fit into this framework: ValueBoxEditor (used by any ValueBoxBase widget) will report an error if the ValueBox's getValueOrThrow throws, and ValueBoxEditorDecorator will wrap any ValueBoxBase display the error next to it (it's more a proof-of-concept though, and not really usable as-is).

If you want to e.g. validate some text against a regexp, it's then as easy as creating a ValueBoxBase<String> (possibly a TextBox subclass) and overriding getValueOrThrow to validate and throw when appropriate.
Reply all
Reply to author
Forward
0 new messages