aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring Validation" Watch "Spring Validation" New topic
Author

Spring Validation

Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
I would like to introduce model layer validation, external to the business object beans being validated themselves, that can be accessed and shared by view layer technologies - currently Struts but possibly JSF in the future.

From reading so far I'm a bit confused as to what the best approach is. For example, do I use: Commons Validator, Spring Validator, or something else (even considered custom AOP implementation but this must surely be a bad idea)?

Struts validation seems easiest but I would like to avoid duplication of the validation rules across applications sharing the same model layer. I would also ideally avoid a completely new approach in the event of using a different view layer (e.g. JSF).

The posts / articles I've seen so far suggest that Commons Validator might be the way to go - I'd like to try this but I'm struggling to find a good explanation of implementation details. I need to know how to specify the validation rules making them available from the Spring model layer configuration and usable for validation from the Struts actions.

Please does anyone have any good links for this information?

Thanks,
Simon
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Simon,

This thread Spring framework, module and Jakarta Commons discusses some related stuff.
Does any of that apply to your situation?


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
Thanks Sonny,

I saw that post when I was looking around prior to posting myself. It did look like the most relevant but what I couldn't see was how I could make the validation rules available through the Spring framework to both Spring business layer classes (to do the back end validation in the model), and to a Struts front end (to use exactly the same validation rules for Struts form validation). I'm trying to get away from having validation for a field entry being specified separately for the model and control layers.

It might be that I'm asking for something that is not a good idea to do in practise, or that I missed some key point in the referenced post / blog article linked from it. Validation is not an area I've looked into much - I've just tended to validate programmatically in the model and use Struts validation for the application, allowing each to look after itself independently but focusing on the model protecting itself.

Simon
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Simon,

I am not sure I understand fully. The server side validation, if that is what you mean by backend validation, is also going to be invoked by the MVC framework you are using, be it Spring MVC or Struts.

Unless, at some point, you are calling the validator, in a dao or manager/service object perhaps...hmmm

Sorry, I have no experience in Struts. But I think, for this kind of detail, you would be much better off posting at the Spring forums.

Sonny
Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
Hi Sonny,

That's exactly what I meant - the business objects calling the same validation as the application. The business object (model layer) validation would primarily exist to protect the model from the applications that use it. The application validation will exist to make the user experience of those validation rules easier - this might be Struts, JSF, or other view layer technology. The key point is that the view layer validation should apply the same rules as the model layer validation, but that model layer validation should hold for every view layer that uses it.

Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Validation
 
Similar Threads
JSF integration to Spring model layer
Spring framework, module and Jakarta Commons
Spring vs JSF
Struts v. Spring
server side validations