user2147970
user2147970

Reputation: 412

GWT validation (JSR 303) SampleValidatorFactory

I try to use bean validation in GWT. I follow this guide : https://developers.google.com/web-toolkit/doc/latest/DevGuideValidation

At compile time, I have the following error :

ERROR: Could not load deferred binding result type 'com.google.gwt.sample.validation.client.SampleValidatorFactory'

I can make it working if I include this dependency:

<dependency>
  <groupId>com.googlecode.gwt-validation</groupId>
  <artifactId>gwt-validation</artifactId>
  <version>2.1</version>
</dependency>

But I find it weird because this dependency is not mentionned in the guide.

Question : As GWT 2.5 is supposed to support bean validation, why do I need this additional library? What am I doing wrong?

I am using GWT 2.5.0

My pom.xml contains the following dependencies :

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.3.1.Final</version>
  <type>jar</type>
  <classifier>sources</classifier>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.3.1.Final</version>
  <type>jar</type>
</dependency>

<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <version>1.0.0.GA</version>
  <type>jar</type>
  <classifier>sources</classifier>
</dependency>

<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <version>1.0.0.GA</version>
  <type>jar</type>
</dependency>

and my gwt.xml contains the following lines :

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

In the code, I get the Validator in this way :

import javax.validation.Validator;
...
private static final Validator VALIDATOR= Validation.buildDefaultValidatorFactory().getValidator();

Upvotes: 1

Views: 1092

Answers (1)

appbootup
appbootup

Reputation: 9537

You are mixing a third party library gwt-validation with Native GWT Validation. The gwt-validation is not from official gwt team or google. You should not be using following in your pom if you intend to stick to native gwt validation support.

<dependency>
  <groupId>com.googlecode.gwt-validation</groupId>
  <artifactId>gwt-validation</artifactId>
  <version>2.1</version>
</dependency>

Also note that you have native gwt hibernate validator support upto 4.1.0 only. GWT Sample usage. GWT native hibernate validator source code.

And you can include it as

<!-- Hibernate bean validation binary for the server -->

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.1.0.Final</version>
  <exclusions>
    <exclusion>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<!-- Hibernate bean validation source for the GWT client -->

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.1.0.Final</version>
  <classifier>sources</classifier>
  <exclusions>
    <exclusion>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<!-- Required by Hibernate validator because slf4j-log4j is
     optional in the hibernate-validator POM
 -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>

Upvotes: 2

Related Questions