-->
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: Using script expressions for object validations
PostPosted: Mon Aug 24, 2009 5:45 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi all,

recently I built a constraint annotation that allows to use statements written in script languages such as Groovy for object validation (inspired by the @Assert annotation of the OVal framework).

Using this annotation, constraints referring to multiple attributes of a bean can easily be expressed, as in the following example:
Code:
@ScriptAssert(lang = "groovy", script = "_this.startDate.before(_this.endDate)")
public class CalendarEvent {

    private Date startDate;

    private Date endDate;

    //constructor, getters and setters ...

}



More information can be found in my web log at http://musingsofaprogrammingaddict.blog ... ation.html. I'd be happy on any feedback, ideas for improvement etc.

Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Using script expressions for object validations
PostPosted: Thu Sep 03, 2009 1:50 pm 
Newbie

Joined: Tue Jul 21, 2009 2:57 pm
Posts: 8
i implemented a class-level constraint with OGNL expressions. seemed like a universal kind of use-case. of course, i then realized that most of our constraints could be replaced with this alone.


Top
 Profile  
 
 Post subject: Re: Using script expressions for object validations
PostPosted: Fri Sep 04, 2009 5:19 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
There is also a JSR 223 compatible engine for OGNL, so the ScriptAssert annotation should work with OGNL as well (haven't tried it out, though). I think, I still would use custom class-level constraints in more complex cases, as they provide more compile-time safety.

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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.