views:

312

answers:

6

We are currently searching for a java framework , that made validation easily on server side and both client side,Spring,Hibernate,Play are the framework choices that we are searching,we are using annotation based development and this framework will determine our javascript choice too.Which is better framework (architecturally) at validation operations on both client side and server side?

+1  A: 

There's GWT Validation. It's designed to bridge client-side and server-side validation.

Jeff
A: 

I would say Spring framework is the best. We have been using Spring - Hibernate combination for a while now.

vinaynag
+4  A: 

Client-side validation (assuming by "client-side" you mean javascript-based) is a myth. It makes for a nicer UI - no question - but it can't be called "validation" because anything that comes from the client can not be assumed valid; not until it's validated on the server.

Server-side validation is not a monolithic piece either - there are at least 3 components to it:

  1. Data storage constraints (e.g. not null, max length, uniqueness, referential integrity, etc... specified at the database level).
  2. Domain model validation (ensuring your entities are valid)
  3. Client input validation (UI and, to lesser extent, API- based validation)

It's possible to derive #1 from #2 - Hibernate Validatior does an excellent job at that assuming you're using Hibernate as your JPA provider.

It's also possible to derive client-side checks from #3. If you intend to use GWT then using GWT VF recommended by Jeff is a good approach as it's based on the same spec (JSR-303) as Hibernate Validator. If you're going to use something else, it's reasonably straightforward to write code generating necessary scriptlets from either annotations or XML-based validation rules. I've done it for ExtJS controls in the past.

The biggest problem is bridging #2 and #3 - the same domain entity may be represented by many different views in UI, each with their own validation rules; said validation rules may be conditional upon entity state and change dynamically, etc... AFAIK there's no good way to do it automatically unless your UI is of very simplistic 1-to-1 CRUD type.

ChssPly76
+2  A: 

Adding to ChssPly76, You can use your Hibernate validation (or javax.validation in the last version) annotated entities directly in your UI, applying the same validation rules automatically also if you use RichFaces. It has a component called beanValidator, which reads the aforementioned annotations.

RichFaces (and JSF), unlike GWT, allows for more document-style web-pages, rather than application-style.

Bozho
+3  A: 

The new Spring 3 (which is at RC2 and should soon be finalized) has a number of goodies to help your cause when matched up with Hibernate. It is common to validate a model after binding user input to it. Spring 3 provides support for declarative validation with JSR-303. This support is enabled automatically if a JSR-303 provider, such as Hibernate Validator, is present on your classpath. When enabled, you can trigger validation simply by annotating a Controller method parameter with the @Valid annotation:

@RequestMapping(value = "/appointments", method = RequestMethod.POST)
public String add(@Valid AppointmentForm form, BindingResult result) {
    ....
}

public class AppointmentForm {

    @NotNull @Future
    private Date date;
}

After binding incoming POST parameters, the AppointmentForm will be validated; in this case, to verify the date field value is not null and occurs in the future.

So this makes validation against your domain model pretty easy and you are free to use any Javascript library in the front end whether Jquery or Extjs etc. I've used Extjs's widgets extensively with Spring with out any lack of flexibility, I expect the same of Jquery and any other for that matter. There is also Spring-js which you can look into and assess its merits for your use case.

non sequitor
can you give some more detail , i create the form object class which has name,mail,text fields then i create formcontroller to use Valid annotation , i couldnt understand how to implement that and use it with form.
Burak Dede
@Burak: You should get what you need here http://static.springsource.org/spring/docs/3.0.0.RC2/spring-framework-reference/html/ch05s07.html
non sequitor
A: 

You could also look for a JSF component library with an ajaxical sauce. They however mostly do server side validation only, but uses ajax for that. Examples are RichFaces (also included in Seam), PrimeFaces and IceFaces.

BalusC