-->
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.  [ 13 posts ] 
Author Message
 Post subject: Proposal: multiple beanvalidators of the same type
PostPosted: Wed Dec 20, 2006 10:28 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
I have a suggestion for the following problem:
I created an Validator to check if a 'date'> 'another date'

The annotation looks like this:
@After(property="endDate", after="beginDate", message="End should be after begin")

Since it involves 2 properties, it is a class-level validation.

Now....
I want multiple 'after' validations on a single bean.
But that is not possible (you can only place an annotation once on a class).

My proposal is to add an annotation 'Validations':

@Validations( {@After(...), @After(..)} )

I could do the multiple validations in a single validatorclass, but I want all the messages added to the invalidValues array, not a single message.

This change would also require changes in the ClassValidator class.

What do you think of this proposal? Should I add it to Jira (I can propably implement it if there are no objections to the required changes)

Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 7:52 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a JIRA issue, it makes sense

_________________
Emmanuel


Top
 Profile  
 
 Post subject: jira issue created
PostPosted: Thu Dec 21, 2006 4:24 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
http://opensource.atlassian.com/project ... se/ANN-513

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 4:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi Edwin,
If you come up with a patch (+ test), I'll include it with 3.2.2 :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Will do
PostPosted: Sat Dec 23, 2006 9:48 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
I will submit the patch end of next week (it'll have to wait untill after Christmas:-)

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 10:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
fantastic :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Object Validation
PostPosted: Sat Dec 30, 2006 1:15 am 
Newbie

Joined: Thu Dec 28, 2006 5:24 pm
Posts: 14
I have this exact problem, but I think of it a little differently; I see the problem of providing semantic object validation. It is one thing to validate individual fields, but it is yet another to validate the object as a whole.

See my post in the JBoss Seam forum on Object Validation.

Can validators be used to annotate at the class level?


Top
 Profile  
 
 Post subject: Oh oh, troubles....
PostPosted: Thu Jan 04, 2007 5:22 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
I'm afraid it isn't going to work...
Let me explain:

I want to define a list of 'validations' on the classlevel.
But, an annotation can only have an array of another concrete annotation-type. (This is a language limitation, you cannot extend annotations and use the 'super' class for the collection of validations)

Example, I can create a 'validations' annotation like this:

Code:
public @interface Validations {
   Required [] validations();
}

This means, I can only add 'required' validations to the list, not other types of validations.


This is not possible:
Code:
public @interface Validations {
   Validation[] validations();
}
...
usage:
@Validations ( validations = {@Required(prop="startDate",message="Start date is required"), @After(prop="endDate",other="BeginDate",message="bla"} )



Now, I'm toying with the idea of allowing a classvalidator to return an array of InvalidValue objects.
This is however very different from the current way the validations work (=specify the messagekey in an annotation).

Don't know if this will be an accepted approach.

Edwin

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject: Re: Oh oh, troubles....
PostPosted: Thu Jan 04, 2007 7:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
evdelst wrote:
Now, I'm toying with the idea of allowing a classvalidator to return an array of InvalidValue objects.
This is however very different from the current way the validations work (=specify the messagekey in an annotation).

Don't know if this will be an accepted approach.

Edwin

I don't understand.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Object Validation
PostPosted: Thu Jan 04, 2007 8:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
awhitford wrote:
Can validators be used to annotate at the class level?


yes
Code:
@MyValidator
public class MyEntity { ... }

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 8:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Edwin, see my comment on the JIRA issue. There might have a workaround

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Patch is attached to the JIRA issue
PostPosted: Mon Jan 08, 2007 3:09 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
I attached the patch to the JIRA issue

Edwin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 08, 2007 1:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
thanks!

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.