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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -