我找不到obj.confirmPassword
始终为空的原因。
如果confirmPassword
不是瞬变的一部分,那么一切正常。
String confirmPassword
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService', 'confirmPassword']
static constraints = {
username blank: false, unique: true, minSize: 4, maxSize: 64
password blank: false, nullable: false, minSize: 4, maxSize: 64, validator: {password, obj ->
def password2 = obj.confirmPassword
password2 == password ? true : ['invalid.matchingpasswords']
}
userFullname blank: false, minSize: 4, maxSize: 64
}
调用save()时抛出NullPointer:
String confirmPasswordField
static transients = ['springSecurityService', 'confirmPasswordField']
static constraints = {
confirmPasswordField bindable: true, nullable:true, blank: false
username blank: false, unique: true, minSize: 4, maxSize: 64
password blank: false, nullable: false, minSize: 4, maxSize: 64, validator: {password, obj ->
def confirmPassword = obj.confirmPasswordField
confirmPassword == password ? true : ['invalid.matchingpasswords']
}
userFullname blank: false, minSize: 4, maxSize: 64
}
如果我评论有关confirmPasswordField的所有内容 - save()就可以了。
答案 0 :(得分:0)
出于安全考虑,瞬态不再是自动绑定的。但是您可以通过添加“可绑定”约束来轻松地使其工作(请参阅http://grails.org/doc/latest/ref/Constraints/bindable.html)。您可以像这样使用confirmPassword。
confirmPassword(bindable: true, nullable:true, blank: false)