Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 域内的域_Grails_Groovy - Fatal编程技术网

Grails 域内的域

Grails 域内的域,grails,groovy,Grails,Groovy,我有两个域类:- class Product { ProductType productType int openingQuantity int unitQuantity Date dateCreated Date lastUpdated boolean active static constraints = { productType(blank:false,nullable:false) openingQuantity(blank:false, n

我有两个域类:-

class Product {
  ProductType productType
  int openingQuantity
  int unitQuantity
  Date dateCreated
  Date lastUpdated
  boolean active
  static constraints = {
    productType(blank:false,nullable:false)
    openingQuantity(blank:false, nullable:false)
    unitQuantity(blank:false, nullable:false)
    active(nullable:false)
    dateCreated()
    lastUpdated()
  }
}


当我在create.gsp的产品。它在下拉列表中将productType显示为id。但我的要求是在下拉列表中显示ProductType名称。任何人都可以提供帮助。

您可以在ProductType类上重写toString

String toString() { name }
或者,假设您使用的是默认脚手架,请更改:

<g:select name="productType.id"
          from="${com.ten.hp.his.pharmacy.ProductType.list()}"
          optionKey="id"
          value="${productInstance?.productType?.id}" />

您可以覆盖ProductType类上的toString

String toString() { name }
或者,假设您使用的是默认脚手架,请更改:

<g:select name="productType.id"
          from="${com.ten.hp.his.pharmacy.ProductType.list()}"
          optionKey="id"
          value="${productInstance?.productType?.id}" />

是的,我可以做,但我不想在域名上做。您能推荐一些视图中的内容吗?@AB您当前使用哪些标签来显示视图中的字段?如果您希望在那里应用更改,那么视图的代码可能会有所帮助(而不仅仅是发布您的域)。这是默认生成的脚手架。它将产品类型id显示为下拉列表。@AB将
optionValue=“name”
添加到
g:select
Yes我可以这样做,但我不想在域中这样做。您能推荐一些视图中的内容吗?@AB您当前使用哪些标签来显示视图中的字段?如果您希望在那里应用更改,那么视图的代码可能会有所帮助(而不仅仅是发布您的域)。这是默认生成的脚手架。它将产品类型id显示为下拉列表。@AB将
optionValue=“name”
添加到
g:select