You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@bval.apache.org by Umesh Awasthi <um...@gmail.com> on 2013/10/17 17:11:31 UTC

Class level constraints not working as expected

Hi All,

Testing a class level constraint, though it seems working fine but getting
issue while displaying errors to the user end.here is my constraints
declaration.

Underlying validator is working as expected , but when i am trying to show
this to UI, it not working.
Since constraints defined is at class level like

@FieldMatch.List({
    @FieldMatch(first="name",second="confirmName")

})

so i was expecting that
violation.getPropertyPath().iterator().next().getName() will give me null,
but it is not giving me null.

I have placed validation on Controller as
@Valid
private DonorProfileDTO donorProfileDTO;
// getter and setters

and violation.getPropertyPath().iterator().next().getName() is giving me
value as
donorProfileDTO.

I have pasted my validation code at Pastebin and here is link for same
Custom Validator Code <http://pastebin.com/vTg5FFdi>

Not sure why it is not working as expected.

-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Class level constraints not working as expected

Posted by Umesh Awasthi <um...@gmail.com>.
Thanks Maat,
I figured it out :)


On Fri, Oct 18, 2013 at 12:57 AM, Matt Benson <gu...@gmail.com> wrote:

> It's because you're validating your Controller as your root object and the
> DTO is being validated by the @Valid annotation.
>
> Matt
> On Oct 17, 2013 10:12 AM, "Umesh Awasthi" <um...@gmail.com> wrote:
>
>> Hi All,
>>
>> Testing a class level constraint, though it seems working fine but
>> getting issue while displaying errors to the user end.here is my
>> constraints declaration.
>>
>> Underlying validator is working as expected , but when i am trying to
>> show this to UI, it not working.
>> Since constraints defined is at class level like
>>
>> @FieldMatch.List({
>>     @FieldMatch(first="name",second="confirmName")
>>
>> })
>>
>> so i was expecting that
>> violation.getPropertyPath().iterator().next().getName() will give me
>> null, but it is not giving me null.
>>
>> I have placed validation on Controller as
>> @Valid
>> private DonorProfileDTO donorProfileDTO;
>> // getter and setters
>>
>> and violation.getPropertyPath().iterator().next().getName() is giving me
>> value as
>> donorProfileDTO.
>>
>> I have pasted my validation code at Pastebin and here is link for same
>> Custom Validator Code <http://pastebin.com/vTg5FFdi>
>>
>> Not sure why it is not working as expected.
>>
>> --
>> With Regards
>> Umesh Awasthi
>> http://www.travellingrants.com/
>>
>>
>>
>


-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Class level constraints not working as expected

Posted by Matt Benson <gu...@gmail.com>.
It's because you're validating your Controller as your root object and the
DTO is being validated by the @Valid annotation.

Matt
On Oct 17, 2013 10:12 AM, "Umesh Awasthi" <um...@gmail.com> wrote:

> Hi All,
>
> Testing a class level constraint, though it seems working fine but getting
> issue while displaying errors to the user end.here is my constraints
> declaration.
>
> Underlying validator is working as expected , but when i am trying to show
> this to UI, it not working.
> Since constraints defined is at class level like
>
> @FieldMatch.List({
>     @FieldMatch(first="name",second="confirmName")
>
> })
>
> so i was expecting that
> violation.getPropertyPath().iterator().next().getName() will give me null,
> but it is not giving me null.
>
> I have placed validation on Controller as
> @Valid
> private DonorProfileDTO donorProfileDTO;
> // getter and setters
>
> and violation.getPropertyPath().iterator().next().getName() is giving me
> value as
> donorProfileDTO.
>
> I have pasted my validation code at Pastebin and here is link for same
> Custom Validator Code <http://pastebin.com/vTg5FFdi>
>
> Not sure why it is not working as expected.
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>
>