【问题标题】:Grails Custom Validator on Property From Another Domain Class来自另一个域类的属性的 Grails 自定义验证器
【发布时间】:2012-07-06 08:50:16
【问题描述】:

Grails 2.0 的新手,如果在评估中创建 custid 在客户中的自定义验证器,我们将不胜感激。只有现有客户才能完成评估。谢谢!

类客户{

String custId
String firstName
String lastName

static constraints = {
    custId()
    firstName()
    lastName()
}

}

类评估{

String custId
String comment

static constraints = {
    custId()
    comment()
}

}

【问题讨论】:

    标签: grails-validation


    【解决方案1】:

    我建议稍微重新设计并将 Customer 的实例传递到您的评估对象中。然后在评估类中,创建一个验证以确保客户不为空。这样做是利用 Customer 类验证来确保您拥有一个“有效”的客户 ID,无论如何您都需要拥有该 ID,以便从我假设您从 Web 获取的 custId 中查找/实例化一个 Customer 对象正在提交表单。

    class Evaluation {
      Customer customer
      String comment
    
      static constraints = {
        customer nullable: false
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-17
      • 2011-01-28
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多