views:

72

answers:

3

Hi All...

I am working on grails project where I need to apply server side validations.

For client side validations I have created basic validation.js file which contains all the javascript functions.

Now what should be the ideal way to achieve the server side validation using Ajax, to achieve the validations like Record Duplication check.

Thanks in advance....

+1  A: 

I do it like this; Create a controller with a method (closure) and call it using Ajax. It then returns map with a success false or true, and a optional msg. You than handle it in js code.

lvojnovic
+1  A: 

Generally, I don't like to post links to solutions but there is quite a bit of code involved so read my article here: http://groovy.dzone.com/articles/better-scaffolding-jquery-part-0

It will show you exactly how to do what you are wanting.

Gregg
+2  A: 

I'd recommend reversing your approach and using the Remote Constraints plugin: http://grails.org/plugin/remote-constraints

It lets you write your validation on the server side (as Domain class constraints) and then generate client side ajax validation so a message is shown when the user tabs off an input field.

cheers

Lee

leebutts