Externalise validation rules JSF - java

we want to do business rule validation outside our java code using some xml etc.we are using Spring 3.1 and JSF 2.0.i tried to search but cudn't found concrete on placing business rule outside our java code.i will thankful if someone can provide direaction for this

I know this isn't exactly what you are looking for but you can use Hibernate annotations in place of hard coded validators in JSF 2.
These are just a few examples of this.
http://weblogs.java.net/blog/urubatan/archive/2006/09/aspectj_hiberna.html
http://docs.jboss.org/seam/1.1GA/reference/en/html/validation.html

Related

Adding spring to servlet just for validation

I am currently not using any frameworks (other than bootstrap) for my java-ee application. But i came across a problem in using server side validation for servlets. I am finding it difficult to implement validation like this
http://spring.io/guides/gs/validating-form-input/
I could use request dispatcher, but I am not sure if it's the right way.
So i wanted to ask is it advisable to use the spring framework just for the validation?
is there any way to convert my entire java application to use spring or should i build the application from the ground up again?
If you just need the validation, then I recommend to use JSR-303/349 Bean Validation 1.0/1.1. The default implementation is done by Hiberante-Validator (this is NOT the Hibernate-ORM project!). It is relative easy to use out of the box.
http://hibernate.org/validator/documentation/getting-started/

Hibernate/JPA/Seam - Validate an Entity Programmatically?

I have an entity in my JBoss Seam-based project that makes use of Hibernate Validator annotations throughout. Although I've got directives in my JSF pages to require elements, etc. I'd like to be able to do one last failsafe validation before calling entityManager.persist() and ending up with a validation exception.
Is there any way to validate the entity programmatically? I've never worked that deeply with Hibernate/JPA, so I'd love to hear any recommendations for getting this working. Thanks!
Bean Validation API supports programmatic usage, see, for example, Hibernate Validator Reference.
If you are using JSF, you can have the validation to occur before your business method is called. If you are not seeing this, I would review the setup, as it should happen automatically and you wouldn't need to manually perform the validation. But you can do that, as you can see in axtavt's answer.

Does spring have a validation framework module that can be used in any layer for validatons?

For instance, I am using JSF + custom framework developed in our company. Now I want to use a third party validation framework that can be used as an plug-in and it should not create any dependency what ever may be the technical stack.
So my question is does spring provide any framework of that sort or if it's available how can I use that?
I am expecting a validation framework something like, which is configurable through XML.
Spring does have a validation framework, but if you want minimal dependencies, then I'd suggest that you go with a Bean validation provider. It's a new(ish) official validation standard, defined in JSR-303.
There are several implementations at the moment. I'd give Hibernate Validator a look.
I disagree. Hibernate Validator is an awful piece of software (at least the versions that were current about a year ago). Spring Validation is a nice piece of software, that goes together well with the BeanWrapper interface.
But it's true: Spring Hibernate resides inside the Spring Context jar, which is unnecessary overhead. Hopefully there will be a separate version sometime.

Does Java Spring 3.0 MVC support annotation/attribute based client side validation like Asp.net MVC 2.0?

In Asp.Net MVC 2.0, at least in the beta, you could decoration your model classes with data annotation attributes and enable client side validation that leverages that criteria defined in your model data annotation attibutes. Is there anything similar for Java Spring MVC 3.0?
Is it possible to inject a component into the response pipeline that can inspect the model's annotated properties and render client side validation logic to complement the server side validation logic that is invoked prior to the controller handling the request?
Actually, there is something a little bit like it, based on the JSR-303 Bean Validation spec, which is now final and fully supported by Spring 3.0.
Recently, as part of Spring Webflow, Springsource has released Spring JS (javascript) which uses Dojo. You can use that for your client side validation. Check out this howto
Obviously, component-frameworks such as Wicket (like fraido mentioned) have better support for this kind of usecase. So if you have to implement a lot of similar usecases, that is probably a better fit for your project. However, if it is sporadic, Spring JS / Bean validation could be the way to go.
Spring MVC is a fairly low level framework. It doesn't extend to doing client side validation.
There are other Java Web frameworks that do this such as Tapestry, Wicket and JSF (IceFaces, etc). These are what I tend to call "component frameworks".
In Spring MVC 3.0 there's nothing like that at the moment. As cletus said frameworks like Tapestry (ex), Wicket (ex) and others have some sort of Client Validation that uses JavaScript to validate forms etc.
You can write your own validation Jstl taglib maybe with the help of a JS Library (jQuery, ...) and Plugins like : jQuery Validation Plugin
edit: I've just found this: Mediawidget. Maybe it's worth having a look.
It says: "Metawidget reads Bean Validation annotations and generates forms with
widgets that are pre-configured for minimum/maximum values, lengths etc."
Spring integration Link1, Link2
This project looks to be exactly what you're looking for: http://kenai.com/projects/jsr303js
2011-12-06: I'm just about to try it myself
2013-12-09: Update on this answer: I did try the library out, and it worked very well. It needed some tweaking (it's a prototype patch for Spring, not a finished plugin), but it was the best solution I could find at the time. Perhaps there is a new solution, or perhaps someone has finished off this prototype since I posted? If not, I can recommend this one.
Ok, this is a variation on what's already been said, but one of the big strengths of Spring-MVC is its ability to integrate with other libraries, like the different JSF variations that do give client side validation.

Java Validation Frameworks

I once came across a validation framework for java, where you wrote one method that protected the integrity of the data-type and any CRUD operations on that data-type automatically called this method.
Does anyone know what this framework is? I simply want to avoid repetitive validation on every CRUD method attached to a data-type.
Here's a huge list of Java Validation Libraries / Frameworks - http://java-source.net/open-source/validation
Apache Commons has a validation framework.
Are you using Hibernate for persistence? If you are, there is Hibernate Validator.
Spring has a very nice validation and binding API.
Hibernate Validator, per adref's answer, is an implementation of JSR-303. Here's a helpful article to get you started if you are interested:
http://java.dzone.com/articles/bean-validation-and-jsr-303

Categories

Resources