English 中文(简体)
gsp 中将 enum 显示为无线电按钮
原标题:show enum as radio button in gsp
  • 时间:2012-05-23 12:29:06
  •  标签:
  • grails

在我的域类,我有一个 enum:

class Product{
  Type type
  enum Type{
    MEDICINE, NON_MEDICINE
  }
}

通过生成默认视图, 这将显示为创建. gsp 页面中的下拉。 我的要求是将其显示为创建页面中的收音机组, 这样我就可以点击收音机按钮来选择其中的任何一个值。 任何人都可以提供一些帮助 。 Thnks

最佳回答

这项工作应:

<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>

这将取代 g:select 中当前在 grails-ap/view/ product/_form.gsp 中的

问题回答

尝试

<g:radioGroup name="type" values="${[ MEDICINE ,  NON_MEDICINE ]}" value="${currentInstance.type}" labels="${[ Medicine ,  Non medicine ]}">
<span>${it.label} - ${it.radio}</span>
</g:radioGroup>




相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签