Grails custom validator syntax inside a command object -
i saw example following syntax used in customer validator inside logincommand object.
password blank:false, validator: { val, cmd -> if(cmd.user && cmd.user.password != val) return "user.password.invalid" }
my understanding here in if
clause, checking 2 things. first, user exists, , second, password of user matches password held logincommand. doesn't seem redundant check if user exists? mean if user didn't exist wouldn't cmd.user.password
null , hence test fail? why user check necessary?
and if necessary, can't encapsulate first user existence check in second check using syntax cmd.user?.password != val
?
i mean if user didn't exist wouldn't cmd.user.password null , hence test fail?
no. if user didn't exist cmd.user.password
throw nullpointerexception.
and if necessary, can't encapsulate first user existence check in second check using syntax cmd.user?.password != val?
you could. matter of style. whichever think more readable.
Comments
Post a Comment