如何在 grails 中为 select(组合框)使用和创建标签库

How to use and create tag library for select (combobox) in grails

我是 grails 的新手,我想做的是将数据元素从枚举 class 加载到 select(组合框),然后为其创建一个标签库。

标签库class

package feedback
import imocha.project.Feedback
import imocha.project.FeedbackType

class FeedbackTagLib {
   static namespace = "l"

    def enumFeedbackType ={attrs, body ->
        attrs.name = "type"
        attrs.from = "${FeedbackType.values()}"
        out << g.select(attrs.name, attrs.from, attrs.value, attrs.optionKey)
    }
}

枚举class

public enum FeedbackType {
    CLA('Complaint'),
    CLE('Complement'),
    ENQ('Enquiry')

    final String value
    FeedbackType(String value){ this.value = value }

    @Override
    String toString(){ value }
    String getKey() { name() }

}

我用这个调用了 GSP 中的标签库

<l:enumFeedbackType value="${feedbackInstance?.type}" optionKey ="key" />

这是错误

URI /feedback/feedback/create
Class groovy.lang.MissingMethodException
Message No signature of method: org.codehaus.groovy.grails.web.pages.GroovyPage.select() is applicable for argument types: (java.lang.String, org.codehaus.groovy.runtime.GStringImpl, null, null) values: [type, [Complaint, Complement, Enquiry], null, null] Possible solutions: collect(), getOut(), inspect(), every()

这应该有效:

def enumFeedbackType ={attrs, body ->
    attrs.name = "type"
    attrs.from = FeedbackType.values()
    out << g.select(attrs)
}