kohiro / gwt-ent

Automatically exported from code.google.com/p/gwt-ent
0 stars 0 forks source link

Failure when trying to use @Size Validation #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi guys,
I just discovered your project and think it's some great piece of work you have 
achieved here. I wonder though why it's so hard to find when googleing for 
databinding...
Anyways, I ran into a Problem when testing your Validation features:

What steps will reproduce the problem?
1. Using the @Size(min=5) (javax.validation.constraints.Size) Anntotation on 
any attribute of a Pojo
2. Binding that attribute via UIBinding to a GWT TextBox Widget
3. Run the application and change the value of the TextBox

What is the expected output? What do you see instead?
Expected: Validation of InputString (size>5)
Instead:
When the Validation is invoked following Exception is thrown:

your class (javax.validation.constraints.SizeValidator) should have reflection 
information before this opeartion. This can be done by annotated class with 
"@Reflectable" annotations, i.e: "@Reflectable", "@Reflect_Domain", 
"@Reflect_Full", "@Reflect_Mini", "@Validtable", "@DataContract" or implement 
flag interface "Reflection". if you are facing the class which you can not 
modify(i.e java.*, javax.*), you can using @Reflectable(relationTypes=true) or 
@Reflect_Domain to your class. Current message is : 
To make ConstraintValidator works with GWT, please makesure its reflection 
enabled. The exception stack trace follows:
com.gwtent.reflection.client.ReflectionUtils$ReflectionRequiredException
    at com.gwtent.reflection.client.ReflectionUtils.reflectionRequired(ReflectionUtils.java:172)
    at com.gwtent.reflection.client.ReflectionUtils.reflectionRequired(ReflectionUtils.java:185)
    at com.gwtent.validate.client.impl.ValidatorGWT.createConstraintValidatorFromAnnotation(ValidatorGWT.java:305)
    at com.gwtent.validate.client.impl.ValidatorGWT.doValidate(ValidatorGWT.java:213)
    at com.gwtent.validate.client.impl.ValidatorGWT.validateValue(ValidatorGWT.java:117)
...

What version of the product are you using? On what operating system?
using GWT 2.0.3 via Maven
using gwt-ent 1.0.0-RC1
included gwt-ent in gwt.xml via
<inherits name="com.gwtent.GwtEnt" />

Please provide any additional information below.
I have Reflection and UIBinding working, so I think I have gwt-ent set up 
correctly.
I investigated the issue quiet a lot and came to the following hints:
-when tying to instantiate the ConstraintValidator for the Size Validation, 
"TypeOracle.Instance.getClassType(clazz);" is called with clazz being set to 
"javax.validation.constraints.SizeValidator"
-this call though returns Null, cause 
"javax.validation.constraints.SizeValidator" is not included in the typeMap of 
TypeOracleImpl
-so I think it has something to do with loading the SizeValidator class into 
the typeMap of the TypeOracleImpl, which must be a setup thing?!
-the @Required Validation workes fine and the RequiredValidator is correctly 
loaded into the typeMap of the TypeOracleImpl

Puhh...long but hopefully helpfull description.
I hope you can give me some hints about what I might have done wrong in project 
setup, sine I don't think it's the wrong use of the Annotation.

Thanks a lot! If I get this to work I will most likely use it in a major 
enterprise project and future contributions in return will be likely.

Original issue reported on code.google.com by nico.rog...@gmail.com on 13 Jul 2010 at 3:08

GoogleCodeExporter commented 9 years ago
Hi, Nico

  Thanks for your nice details. 

  The UIBinding and Reflection working, it's mean your Pojo have reflectable, but for Control JavaScript size, GWTENT provided different reflection level. for example "@Reflectable" is a normal level, "@Reflect_Domain" and "@Reflect_Full" will create full reflection information for that class, to using validation, you need full reflection for your class.

  I will change the Error message to make it more obviously for validation, Thanks you very much. Please let me know how is it going :)

James

Original comment by JamesLuo...@gmail.com on 13 Jul 2010 at 11:34

GoogleCodeExporter commented 9 years ago
Hmm Sorry but that didn't fix my Problem.
I added @Reflect_Full to my Pojo, but nothing changed about the Exception.
The weird thing to me is that it wasn't the Pojo in the first place, that is 
mentioned in the ReflectionNeededException, but that it's the 
javax.validation.constraints.SizeValidator Class.
Or is the strategy behind that to make SizeValidator reflectable through the 
@Reflect_Full Annotation on any Pojo that is Implementing the @Size?

I got one step further by manually adding the SizeValidator class to the 
typeMap of TypeOracleImpl via instantiating a ClassTypeImpl like this:
new ClassTypeImpl(SizeValidator.class);
The SizeValidator can then be retrieved from the TypeOracleImpl when 
validating, but I end up with a NullPointer later, when the constructor is to 
be found, cause of course there is no MetaData for Reflection still :o(

So I still guess that it has to do something with the class loading of the 
Validation stuff. May it be a problem that I have javax validation API lib in 
my classpath too, where all those Validation Annotations are included also?
I didn't think so, cause that's only server-side and GWT-ent is client-side, 
but of course I don't have the complete view of what GWT ent is doing while 
preparing Reflection Information and stuff...

Thanks for your help!

Original comment by nico.rog...@gmail.com on 14 Jul 2010 at 7:18

GoogleCodeExporter commented 9 years ago
Hi, Is it possible that I can have a look your Pojo class? There is a @Size in 
showcase as well but not problems.
If Pojo is fine, then maybe javax validation API is the problem as well.

James

Original comment by JamesLuo...@gmail.com on 14 Jul 2010 at 9:13

GoogleCodeExporter commented 9 years ago
Hi James,

the Pojo Code is the following:

package de.hdi.bin.fub.client.model;

import java.io.Serializable;

import javax.validation.constraints.Size;

import com.gwtent.reflection.client.annotations.Reflect_Full;
import com.gwtent.validate.client.constraints.Required;

/**
 * GWT Model Klasse zur Representation der Kurzform eines VUs.
 * 
 * @author Rogasch
 */
@Reflect_Full
public class VuKurz implements Serializable {

    private static final long serialVersionUID = 1L;

    Long vuNummer;

    @Required
    @Size(min = 5)
    String vuName;

    String vuOrt;

    public Long getVuNummer() {
        return this.vuNummer;
    }

    public void setVuNummer(final Long vuNummer) {
        this.vuNummer = vuNummer;
    }

    public String getVuName() {
        return this.vuName;
    }

    public void setVuName(final String vuName) {
        this.vuName = vuName;
    }

    public String getVuOrt() {
        return this.vuOrt;
    }

    public void setVuOrt(final String vuOrt) {
        this.vuOrt = vuOrt;
    }

}

Original comment by nico.rog...@gmail.com on 14 Jul 2010 at 9:22

GoogleCodeExporter commented 9 years ago
Thanks, the pojo is correct. I will put a separated javax validation jar to my 
gwt compile classpath and try again. will let you know tomorrow. 

Can you try to remove the validation jar from your gwt compile classpath? I 
think that will help :)

Original comment by JamesLuo...@gmail.com on 14 Jul 2010 at 9:57

GoogleCodeExporter commented 9 years ago
Hi James,
I see no chance to remove the validation jar from the project, since it's part 
of a bigger scope and even though it's not directly used in my project, it's a 
dependency of some framework component we use.
Shouldn't there be a way to tell GWT only to use the GWT-Ent classes?
We did something like that with the Apache Commons library.
We override the log4J standard classes so they could also be used on 
client-side(triggering a remote-service that logs the stuff on the server) and 
tell GWT to replace the standard log4j classes with our custom made classes 
when generating the client-side code.
We used the "<super-source path="">" entry in our gwt.xml for that. Are you 
familiar with that configuration?

P.S.: Sorry but my next answer may take a while, since I'm going onto well 
earned vacation for a week, but I may tell a collegue to continue with this 
topic :o)

Original comment by nico.rog...@gmail.com on 15 Jul 2010 at 1:18

GoogleCodeExporter commented 9 years ago
Hi, Nico

  Thank you very much. I will working on this, actually the JSR303 implement here is a subset of JSR303, no all API can be supported in GWT client code. I will review my codes and will let you know how it's going. 

James

Original comment by JamesLuo...@gmail.com on 20 Jul 2010 at 12:10