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

frameworksjakarta-eejavaspring

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?

Best Answer

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.