0

次の方法で、コントローラー内のカスタム taglib にインスタンスを取得しようとする場合:

def myTagLib = grailsApplication.mainContext.getBean('com.mypackage.MyTagLib')

次のエラーが表示されます。

「com.mypackage.MyTagLib」という名前の Bean が定義されていません。スタックトレースは次のとおりです: org.springframework.beans.factory.NoSuchBeanDefinitionException: 'com.mypackage.MyTagLib' という名前の Bean が定義されていません

ただし、組み込みの taglib のインスタンスを問題なく取得できます。

def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib')

以下によると、これはうまくいくはずです。私のtaglibが有効なBeanとして認識されない理由は誰にもありますか?

Grails 2.4.0 を使用しています

4

1 に答える 1

1

According to Section 8.3.5 of the Grails Documentation, if your taglib is namespaced (which is generally a good practice), you can simply call taglib methods by using your namespace as the prefix to the method call.

For instance, if you have a taglib namespaced "my" and it has a method called "smiley" that accepts an attribute "happy", you could have the following line in a controller with no extra imports necessary:

my.smiley(happy: true)
于 2014-08-28T14:28:48.337 に答える