Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Integrating Hibernate Validator with Spring MVC

Remember when I wrote about Better client-side validation with Prototype back in May? Ted Bergeron responded to my post with the following comment:

Now that I am using Hibernate Annotations Validator, I stopped using commons validator. You can use the hibernate validator without using hibernate for persistence. I wrote some jsp 2.0 tag files to handle binding my form fields with spring mvc, and I use reflection to check for the validation annotations. This makes it no work to have a js calendar for all Date fields, or have class="required" added to all fields that have a @NotNull annotation. I'd be happy to send you the code for appfuse 2.0.

Ted followed up by sending me the code. I took a look at it, and reviewed a well-written PDF he'd written for his work. I told him he should publish it as an article, hooked him up with some folks at IBM developerWorks - and voila! Ted's article, titled Hibernate can meet your validation needs was published yesterday. Nice work Ted!

I'm looking forward to trying to leverage Hibernate Validation annotations for all the web frameworks in AppFuse. Should be interesting hacking into the cores of the frameworks to modify how their validation engines work.

Posted in Java at Sep 13 2006, 11:17:46 AM MDT 14 Comments
Comments:

Ughh..That would be nice.

I'll help if you decide to do it to Tapestry. (So long as it's a version I can muck around with via maven2, which is currently only 4.1 )

Posted by Jesse Kuhnert on September 13, 2006 at 07:47 PM MDT #

I'm definitely hoping to do it in Tapestry. We have the Maven 2 conversion mostly done, and if 4.1 is available via ibiblio (and backwards compatible) - you might be able to do it right now.

Then again, I'd rather see TAPESTRY-881 fixed first. ;-)

I should probably start working on Howard's code review issues pretty soon as well.

Posted by Matt Raible on September 13, 2006 at 09:28 PM MDT #

Yeah, 4.1 is available in ibiblio (and backwards compatible)....It's fairly stale now though, so it may be better to wait for a 4.1.1 release(only available in apache snapshot repo right now).

I had forgotten, but apparently there has been some work done in this area already. He says it's compatible with 4.0/4.1. Not sure if there's anything in it you can work from.

http://beanform.sourceforge.net

Posted by Jesse Kuhnert on September 13, 2006 at 09:44 PM MDT #

Ah...Sure. I can fix TAPESTRY-881 now-ish, though it'll be another snapshot repo only release. (The 4.1.1 release should debut sometime before the next ajax experience conference in October.)

Posted by Jesse Kuhnert on September 13, 2006 at 09:46 PM MDT #

The BeanForm Tapestry component (http://beanform.sourceforge.net/) already does this. You could either look at using BeanForm in AppFuse, or extract the code from the BeanForm codebase. It's really not too hard to do because of how much Tapestry rocks ;-) See http://beanform.sourceforge.net/beanform-core/xref/index.html for the code, specifically Integrator, IntegratorChain, HibernateIntegrator and Ejb3Integrator, all in the net.sf.beanform.integration package.

Posted by Daniel Gredler on September 13, 2006 at 10:13 PM MDT #

Very soon (hopefully next week) you'll be able to enjoy hibernate validation in spring by using the new springmodules bean validation framework (part of springmodules-validation module). Actually, the framework ships with its own annotations which are a super set of those hibernate provides. And if you're really keen on using hibernate ones, it picks them up as well. The framework is of course very much Spring oriented and is quite customizable on many levels. Few features:
  • EL support in an @Expression annotation
  • Conditional validation -> @NotNull(apply-if="some condition in el")
  • xml support -> one can override validation defined in annotations using external xml configuration
  • Cascade validation -> like Hibernate's @Valid but more spring oriented.. that is, if an address is being validated within the User validation, the errors will be registered under user.address field
  • i18n -> error codes are registered per class/property (e.g. Person.firstName[not.null]), enabling well structured resource bundles for domain validation messages
  • many more...
cheers,
Uri

Posted by Uri on September 13, 2006 at 10:58 PM MDT #

Uri - I'm glad to see annotation-based validation support added to Spring MVC. Is there a client-side component to this validation framework, or is it purely server-side?

Here's to hoping the JSF and Struts 2 guys leave comments that their frameworks support Hibernate Validation annotations as well. ;-)

Posted by Matt Raible on September 14, 2006 at 12:03 AM MDT #

JBoss Seam makes use of Hibernate Validators in conjunction with JSF. This can occur when EJB3 interceptors are brought into the mix and with EL for runtime validation of metadata. More interestingly though is some of the conversation that Jason's brought up with JSR 303. Basically everyone is doing kind of the same thing under Java 5, but it'd be great if it was standardized such that validations for email, credit cards, numbers, etc could be shared among frameworks from a single business model.

Posted by Jacob Hookom on September 14, 2006 at 06:49 AM MDT #

Uri can you give more information on the extension to Springmodules-validation i.e. confluence page, documentation, etc. I would love to see an example of it. Thanks, Sergey

Posted by Sergey on September 14, 2006 at 07:36 AM MDT #

Unfortunately I didn't have much time to work on it and add the client side support for this release but it's definitely planned for one of the releases to follow.

Regarding documentation... There will be a fairly detailed documentation as part of the springmodules documentation. We're also working on putting the springmodules samples as part of the release (currently the only way to get to them is by checking them out of cvs) where one of the samples shows a very simple example of how to use this framework along with SpringMVC. cheers,
Uri

Posted by Uri on September 14, 2006 at 09:13 PM MDT #

Thanks Uri, I got the source. I will try to figure it out Thanks, Sergey

Posted by Sergey on September 14, 2006 at 09:40 PM MDT #

Just wondering how you would handle multi country support. A zipcode for example would have different formats and therefore different regular expressions to validate with. You would want to put these in an external file to allow for ease of adding extra countries. Cheers, Marc

Posted by Marc on October 17, 2006 at 08:52 AM MDT #

The link to the IBM website is broken. Can anyone provide this interesting article?

Posted by Oliver on February 13, 2008 at 10:04 AM MST #

I asked IBM and they said they were upgrading their systems and would fix the link. That was in December.

So, I posted the article on my own site:

http://www.triview.com/articles/hibernate/validator/canmeetyourneeds.html

Everything is still pretty much current 18 months later. In my own code I re-implemented the tagfiles as subclasses of Spring's classic Taglibs to see if there was a performance difference, and bundled this code as a jar to drop into projects.

I spoke with Keith Donald at the Spring Experience about the article and trying to contribute the code. He said that he would take a look at it. However with the frosty relationship between JBoss and SpringSource, a project integrating SpringMVC and Hibernate probably wouldn't get accepted.

Posted by Ted Bergeron on February 22, 2008 at 07:07 PM MST #

Post a Comment:
  • HTML Syntax: Allowed