Advertisement
dmahapatro

Validator

May 5th, 2013
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.93 KB | None | 0 0
  1. //Contoller
  2. class DemoUrlMappingController {
  3.     def action1(DemoUrlMappingCommand com) {...}
  4.     def action2(DemoUrlMappingCommand com) {...}
  5. }
  6.  
  7. //Command Object
  8. import grails.validation.Validateable
  9. @Validateable
  10. class DemoUrlMappingCommand {
  11.     String userName
  12.     String emailId
  13.     String someOtherParameter
  14.     //Mapped to default 'action' keyword in params
  15.     String action
  16.     static constraints = {
  17.         userName validator: {val, obj ->
  18.             if (obj.action == "action1"){
  19.                 //validate according to action1
  20.             } else if (obj.action == "action2"){
  21.                 //validate according to action2
  22.             }
  23.         }
  24.         emailId validator: {val, obj ->
  25.             if (obj.action == "action1"){
  26.                 //validate according to action1
  27.             } else if (obj.action == "action2"){
  28.                 //validate according to action2
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement