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?
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.
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.
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.
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!