Search code examples
javascriptgwtclient-side-validation

GWT - Simple Javascript for client side validation


I'm new to GWT. Can we write direct JavaScript codes for client side validations? (Afaik, we write Java codes, then it will convert to the JavaScript at runtime. What I want to know is, can we write simple client side validations using our own JavaScripts,without writing Java?)

Thanks!


Solution

  • There is hardly any need to do that.

    1) You have GWT Validation framework for best possible framework approach.

    2) Code your widgets to to do most of the validation in java.

    3) Add your GWT Code validation to change handlers or blur handlers in input widgets.

    4) Always rely on server side revalidation with Request Factory.

    You should avoid mixing gwt widget with javascript validation.

    The last and not recommended approach is to use JSNI - https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI

    This allows you to wrap javascript code in GWT Java. This code cannot be optimized or Unit Tested by GWT. This cannot be browser guaranteed by GWT Java.