Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which java web framework to choose for client side and server side validation?

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?

like image 886
Burak Dede Avatar asked Jun 10 '26 04:06

Burak Dede


2 Answers

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.

like image 133
non sequitor Avatar answered Jun 13 '26 11:06

non sequitor


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.

like image 29
ChssPly76 Avatar answered Jun 13 '26 13:06

ChssPly76



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!