-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Validator: passing context information with @Valid
PostPosted: Wed Oct 19, 2011 4:33 pm 
Newbie

Joined: Wed Oct 19, 2011 3:59 pm
Posts: 2
Hi,

I have the following bean "Test" with cascaded validation to 2 objects of type "Info"
Code:
public class Test {
  .........
  @Valid
  Info creditInfo;
  @Valid
  Info debitInfo
  .............
}
public class Info {
  @CheckAccount(message="Account is invalid")
  String account;
  @CheckCustomer
  String customer(message="Customer is invalid")
  ................
}


I want my messages for constraints on "Info" to also be able to display whether it was "Credit" or "Debit" related.

How can I pass that information from top level bean to the embedded bean?
Any ideas?

Thanks,


Top
 Profile  
 
 Post subject: Re: Validator: passing context information with @Valid
PostPosted: Thu Oct 20, 2011 4:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

unfortunately, there is not simple solution for your problem. Bean Validation cannot know that you are using the Info class in multiple contexts.


Top
 Profile  
 
 Post subject: Re: Validator: passing context information with @Valid
PostPosted: Thu Oct 20, 2011 6:42 pm 
Newbie

Joined: Wed Oct 19, 2011 3:59 pm
Posts: 2
Thanks for the reply.

It would be useful to have a payload for @Valid and that being propagated to the immediate cascaded object.

The only solution that I can think of is to have a custom constraint at class level ("Info"). But, I will have to code for all the validations on the properties of Info within this custom validator. I will lose the ability to externalize the constraints in an xml file or annotations.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.