将枚举显示为gsp中的单选按钮

A B*_*A B 4 grails

在我的域类中,我有一个枚举: -

class Product{
  Type type
  enum Type{
    MEDICINE, NON_MEDICINE
  }
}
Run Code Online (Sandbox Code Playgroud)

通过生成默认视图,这将显示为create.gsp页面中的下拉列表.我的要求是在创建页面中将其显示为一个无线电组,我可以通过单击单选按钮从中选择任意一个值.谁能提供一些帮助.thnks

tim*_*tes 9

这应该工作:

<g:radioGroup name="type"
                  values="${test.Product$Type?.values()}"
                  labels="${test.Product$Type.values()*.name()}"
                  value="${productInstance?.type?.name()}">
  ${it.radio} <g:message code="${it.label}" />&nbsp;
</g:radioGroup>
Run Code Online (Sandbox Code Playgroud)

这应该取代当前g:selectgrails-app/views/product/_form.gsp