2

我在我的 GWT 项目中添加了验证可能性。但它不起作用。每次我尝试验证某些东西时都会收到这些错误:

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'

我的实体.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);
      }
    }

主.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");
  }
...

主.gwt.xml

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

请帮我解决这个问题。

4

0 回答 0