views:

961

answers:

3

Hi all,

Please solve my following confusions about validation in Struts2 -

1) Can we do client side and server side validation through JavaScript ? 2) Can we do client side and server side validation through AJAX ?

If possible then which one is beneficial for client side validation and which one for server side ?

Looking for your reply.

Vky.

A: 

Client side validation can be done through Javascript. Server side validation is done through the validation framework. You can do validation through AJAX but it is a bit more work.

We have found that client side validation is best left to simple cases such as missing mandatory fields and illegal characters. Anything more complex than that needs to be AJAX and/or server side. Also we found the documentation on the Struts 2 client side validation to be less than useful so you may want to consider the validation in your Javascript framework of choice (Dojo, YUI, Scriptaculous JQuery etc).

Peter Kelley
A: 

Yes, you can use both javascript and ajax, and quite often you'll use both - even to validate the same piece of data. (If it passes client side validation you do ajax validation afterwards.)

There's a clear case for using ajax when you do not want the data you need to validate to be present in javascript, where everyone can see it. Client-side validations are usually limited to simpler things.

The disadvantage of all things ajax is that it often increases page complexity quite a lot.

krosenvold
A: 

Do you know Full Hibernate Plugin?

There is a great validation feature in this plugin...

http://cwiki.apache.org/S2PLUGINS/full-hibernate-plugin.html

more at vaannila.com

Yoshi