Grails 如何从另一个命令对象访问命令对象的属性?

Grails 如何从另一个命令对象访问命令对象的属性?,grails,properties,groovy,controllers,Grails,Properties,Groovy,Controllers,我目前正在开发一个grails应用程序。我在控制器中有两个命令对象(AccountInfoCommand和EducInfoCommand)。在我的EducInfoCommand上,我想检查YearDigraded属性是否早于其验证器约束上设置的生日(AccountInfoCommand的属性)。我该怎么做 这是我的AccountInfoCommand的代码: class AccountDetailsCommand implements java.io.Serializable { S

我目前正在开发一个grails应用程序。我在控制器中有两个命令对象(AccountInfoCommand和EducInfoCommand)。在我的EducInfoCommand上,我想检查YearDigraded属性是否早于其验证器约束上设置的生日(AccountInfoCommand的属性)。我该怎么做

这是我的AccountInfoCommand的代码:

class AccountDetailsCommand  implements java.io.Serializable {

    String username
    String password
    String confirmPassword
    String emailAddress
    Date birthDate        
}
class EducInfoCommand implements java.io.Serializable {

    Integer graduated 
    EducationLevel educationLevel   
    String schoolName 
    String yearGraduated
    String honorsReceived
}

static constraints = {

    yearGraduated nullable: false, maxSize:4, blank: false,  matches: /([0-9]*)/,
      validator: {
            Date.parse('yyyy',it) <= new Date() ? true : false
      }
}
这是我的EducInfoCommand代码:

class AccountDetailsCommand  implements java.io.Serializable {

    String username
    String password
    String confirmPassword
    String emailAddress
    Date birthDate        
}
class EducInfoCommand implements java.io.Serializable {

    Integer graduated 
    EducationLevel educationLevel   
    String schoolName 
    String yearGraduated
    String honorsReceived
}

static constraints = {

    yearGraduated nullable: false, maxSize:4, blank: false,  matches: /([0-9]*)/,
      validator: {
            Date.parse('yyyy',it) <= new Date() ? true : false
      }
}
类EducInfoCommand实现java.io.Serializable{ 整数刻度 教育水平教育水平 字符串学名 弦年轮 收到字符串荣誉 } 静态约束={ 可为空:false,maxSize:4,空白:false,匹配项:/([0-9]*)/, 验证器:{
Date.parse('yyyy',it)您需要引用EducInfo所针对的AccountDetails。例如,如果您在
EducInfoCommand
中添加了一个用户名字段,您可以从中查找帐户详细信息(假设有一个AccountDetails gorm对象类似于命令对象):


很抱歉,这不起作用。引发了Null指针异常错误。您需要适当填充用户名字段。鉴于此,您可能应该为其添加nullable:false约束。