Hi Martin,

Sorry for the <head> <body>.
I miss it.

Thanks for your insights.

In the ConstraintIterator's constructor, the set returned by the Hibernate 
validation implementation (Set<ConstraintDescriptor<?>> constraints)
is unordered.

Either by calling
Set<ConstraintDescriptor<?>> constraints = propDesc.findConstraints()
                                        .unorderedAndMatchingGroups(groups)
                                        .getConstraintDescriptors();
                                        
or                              
BeanDescriptor beanDescriptor = 
validator.getConstraintsForClass(IdentityRegistrationModel.class);
PropertyDescriptor propertyDescriptor = 
beanDescriptor.getConstraintsForProperty(property);
Set<ConstraintDescriptor<?>> constraintDescriptors = 
propertyDescriptor.getConstraintDescriptors();

As there are 2 annotations with the same type (Size) per property, 
@Size.List({
        @Size(min=4, message = "{firstName.sizeToSmall}"),
        @Size(max=50, message = "{firstName.sizeToBig}")
})
the last call to SizeTagModifier # tag.put() wins and maxlength may be wrong 
(Integer.MAX_VALUE).

The validation itself, when form is submitted, is OK.
Only the maxlenght may be wrong.   
           

One way to fix this problem :

In the ConstraintIterator's constructor, before populating the stack,
an iteration could be made over the 'Set<ConstraintDescriptor<?>> constraints' 
to find ConstraintDescriptor with Annotation's type = Size,
and if there is more than one, the biggest (=Integer.MAX_VALUE) max value 
should be removed.

The other way is to add an AttributeModifier to the textfield, new 
AttributeModifier("maxlength", new Model<>(50))). 
Which I do.

François








Le 15 sept. 2015 à 21:47, Martin Grigorov <mgrigo...@apache.org> a écrit :

> Hi Francois,
> 
> A miracle happened after adding <head> & <body> HTML elements to
> PageWithForm.html ;-)
> Without <head> Wicket logs an ERROR.
> 
> About Integer.MAX_VALUE - a breakpoint
> at org.apache.wicket.bean.validation.SizeTagModifier#modify shows that this
> method is called twice per property. Once with annotation.max() returning
> MAX_VALUE and second time with the set value(50). Maybe there is a bug at
> Hibernate-Validator
> or org.apache.wicket.bean.validation.ConstraintIterator#ConstraintIterator.
> 
> Enjoy!
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Tue, Sep 15, 2015 at 11:00 AM, Francois Meillet <
> francois.meil...@gmail.com> wrote:
> 
>> Hi,
>> 
>> I have a very strange problem !!!
>> 
>> 
>> A form is created using a model object containing validation annotation
>> constraints.
>> 
>> The model object contains 3 properties (aaaaa, firstName, lastName) with
>> annotations like this
>> 
>> @Size.List({
>> @Size(min=2, message = "{xxx.sizeToSmall}"),
>> @Size(max=50, message = "{xxx.sizeToBig}")
>> })
>> 
>> xxx.sizeToSmall and xxx.sizeToBig key/value are present in the
>> WicketApplication.utf8.properties file
>> 
>> When the form is rendered, the maxlength value may be wrong.
>> 
>> 
>> Actually the maxlength value is only wrong with the property 'firstName'
>> 
>> with the following html
>> <input wicket:id="firstName" id="firstName" type="text"  />
>> <input wicket:id="firstName" id="firstName" type="text" maxlength="50" />
>> 
>> but with
>> <input wicket:id="firstName" id="firstName" type="text" MAXLENGTH="50" />
>> the value will be ok
>> 
>> This only happens with this 'firstName' property !!!
>> 
>> 
>> Environment:
>> -----------
>> Wicket 7.0.0
>> validation implementation : hibernate-validator
>> OSX & jdk 1.8
>> 
>> 
>> here is the quickstart
>> 
>> Thanks for yours suggestions
>> 
>> François
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 

Reply via email to