Search code examples
gwtbean-validationrequestfactoryhibernate-validator

How to do client side validation with annotated rules on domain classes (RequestFactory)?


I've been developing a project with GWT 2.4 and looking for a way to validate (JSR 303) my client (proxy) classes without recreate annotations from my domain classes (server side). I know that there is an example suplied with GWT trunk code (validation), but it doesn't use RequestFactory, it uses RPC.

Is it possible to take validations from domain classes on client side? Would it be the best strategy share my domain model with client code??

As far as I know, GWT team was working on this feature on 2.3 and 2.4. Is it already done, or should I wait for GWT 2.5?

This was already posted on GWT Forum, but it is still without answer.

https://groups.google.com/forum/#!msg/google-web-toolkit/au_GCy_9WZQ/6296p5TcWdoJ

Thanks.

Edit: This is how would it be validation on client side (not tested)...

@UiHandler("save")
void onSave(ClickEvent event) {
    Modulo modulo = new Modulo(); //domain class
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    Set<ConstraintViolation<Modulo>> violations = validator.validate(modulo, Default.class);
    delegate.saveClicked();
}

Solution

  • Best option that I've found is to wait. GWT team is still working on client side validation and it's due end of summer.

    http://code.google.com/p/google-web-toolkit/wiki/BeanValidation

    Comment by project member [email protected], Apr 10, 2012:

    "I have a plan to finish implementing the spec this summer."

    As this application does not have much input data, I have chosen to do the validation only on the server.