Java 为什么标记库测试抛出GrailStageException?

Java 为什么标记库测试抛出GrailStageException?,java,exception,grails,taglib,Java,Exception,Grails,Taglib,假设我有一个TagLib使用FormatTagLib: class MyTagLib { def something = {attrs, body -> def format = new FormatTagLib() out << format.formatDate(attrs.date, format: 'HH:mm') } } 为什么此代码会引发formatDate异常 org.codehaus.groovy.grails.web.taglib

假设我有一个TagLib使用
FormatTagLib

class MyTagLib {

  def something = {attrs, body ->
    def format = new FormatTagLib()
    out << format.formatDate(attrs.date, format: 'HH:mm')
  }

}
为什么此代码会引发
formatDate
异常

org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Tag [formatDate] does not exist. No corresponding tag library found.
有几件事:

  • 您不需要在新的taglib中实例化FormatTagLib
  • 您的标记库中有一个bug,FormatDate采用的是一个映射,而不是日期和映射
  • 如果使用内置特性,Grails会使测试标记库变得简单得多
  • 我认为一个有效的例子是:

    类MyTagLib{
    静态名称空间=“myTags”
    def something={attrs,body->
    
    非常感谢您的关注。是否有什么特别的东西可以将一个域对象作为参数传递给
    applyTemplate
    ?我没有得到这样的属性:
    类的myProperty:org.codehaus.groovy.runtime.GStringImpl
    。applyTemplate的第二个可选参数获取一个映射,用于解释您拥有的任何“模型”对象我已经运行了我发布的代码,测试已经编译并通过了。如果没有具体的例子来说明myProperty的问题,那么很难提供更多帮助。
    org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Tag [formatDate] does not exist. No corresponding tag library found.