2

I added validation possibility into my GWT project. But it doesn't work. I get these errors each time when I try to validate something:

Rebinding com.val.client.SampleValidatorFactory.GwtValidator
Invoking generator com.google.gwt.validation.rebind.ValidatorGenerator
Unexpected error trying to instantiate Generator 'com.google.gwt.validation.rebind.ValidatorGenerator'

MyEntity.java

package com.val.entity;
public class Pravform implements Serializable {
  @Size(min = 4)
  private String pfName;
  ...

SampleValidatorFactory.java

package com.val.client;    
import javax.validation.Validator;
import com.google.gwt.core.client.GWT;
import com.google.gwt.validation.client.AbstractGwtValidatorFactory;
import com.google.gwt.validation.client.GwtValidation;
import com.google.gwt.validation.client.impl.AbstractGwtValidator;
import com.val.entity.*;

public final class SampleValidatorFactory extends AbstractGwtValidatorFactory {
      @GwtValidation(Pravform.class)
      public interface GwtValidator extends Validator {
      }

      @Override
      public AbstractGwtValidator createValidator() {
        return GWT.create(GwtValidator.class);
      }
    }

Main.java

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import com.val.entity.Pravform;
public class Main implements EntryPoint {
  Pravform newPravform = new Pravform(pfNameTextBox.getText());
  Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
  Set<ConstraintViolation<Pravform>> violations = validator.validate(newPravform);
  if (!violations.isEmpty()) {
    tempLabel.setText("Error");
  }
...

Main.gwt.xml

....
<inherits name="org.hibernate.validator.HibernateValidator" />
  <replace-with
    class="com.val.client.SampleValidatorFactory">
    <when-type-is class="javax.validation.ValidatorFactory" />
  </replace-with>
....

Please, help me to resolve this problem.

Valentyn Grygoriev
  • 463
  • 10
  • 29
  • What is the error? When in dev mode, you'll only see a few lines like that, but clicking any line will give more detail. You might find it easier to compile the project and see the full error there. – Colin Alworth Jul 03 '13 at 12:39
  • Error line is `Unexpected error trying to instantiate Generator 'com.google.gwt.validation.rebind.ValidatorGenerator'`. The first 2 lines : `Rebinding com.val.client.SampleValidatorFactory.GwtValidator Invoking generator com.google.gwt.validation.rebind.ValidatorGenerator` are from debugger. – Valentyn Grygoriev Jul 03 '13 at 14:11
  • Yes, there was hided error information: ` java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider`. I didn't see it at first time. – Valentyn Grygoriev Jul 03 '13 at 14:24
  • Try following that error message - if it doesn't help, share the full error log, any errors available. It may be helpful to compile so you can get the whole set of errors in one log. – Colin Alworth Jul 03 '13 at 15:40
  • The problem was in compatibility versions of hibernate-validator and validation-api. The same problem has viewed here [stackoverflow.com](http://stackoverflow.com/questions/14730329/jpa-2-0-exception-to-use-javax-validation-package-in-jpa-2-0). Thank you, Colin, for directed me in right direction. – Valentyn Grygoriev Jul 04 '13 at 07:47

0 Answers0