1

私は2つのドメインクラスを持っています:-

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()
  }
}

class ProductType {
  String name
  Date dateCreated
  Date lastUpdated

  static constraints = {
    name(nullable:false, blank:false,maxSize:50,validator: {
      return !ProductType.findByNameIlike(it)
    })
    dateCreated()
    lastUpdated()
  }
}

私が製品の create.gsp にいるとき。ドロップダウンにidとしてproductTypeが表示されます。しかし、私の要件は、ドロップダウンに ProductType 名を表示することです。誰でも助けてください。

4

1 に答える 1

1

ProductType クラスで toString をオーバーライドできます。

String toString() { name }

または、デフォルトの足場を使用していると仮定して、次のように変更します。

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

を追加するoptionValueと、次のようになります。

<g:select name="productType.id"
          from="${com.ten.hp.his.pharmacy.ProductType.list()}"
          optionKey="id"
          optionValue="name"
          value="${productInstance?.productType?.id}" />
于 2012-05-22T07:14:33.980 に答える