1

我尝试了按事件提供服务的 platform-core-1.0 rc5 插件。现在我在 grails-plugin "listadmin" 中编写了一个服务:

package listadmin

class SECO_ListenService {

    @grails.events.Listener(topic='getEntriesOfList', namespace='listadmin')
    def getEntriesOfList(String intnalListName) {
        println "SECO_ListenService"
        def Liste aList = Liste.findByInternal_name(intnalListName)
        return aList.eintrage.toList()
    }
}

该服务应返回一个名为“institutionadmin”的其他 grails 插件中的下拉列表。我想将此服务列表用于域模型的下拉列表。我应该提到我使用动态脚手架。现在我尝试在域模型中调用此事件:

package institutionadmin
import org.springframework.dao.DataIntegrityViolationException
class Einrichtung {

    Long einrichtungs_type
    Long type_of_conzept
    int anzahl_gruppen
    int anzahl_kinder_pro_Gruppe
    String offnungszeiten
    static hasMany = [rooms : Raum]
    static constraints = {
        def aList = []
        def reply = event(for:"listadmin", topic:"getEntriesOfList", data:"einrichtung_type").waitFor()

        aList = reply.value.toList()
        einrichtungs_type(inList: aList)
    }
}

如果我尝试运行此应用程序,我会收到以下错误:

由 MissingMethodException 引起:没有方法签名:institutionadmin.Einrichtung.event() 适用于参数类型:(java.util.LinkedHashMap) 值:[[for:listadmin, topic:testEventBus]] 可能的解决方案:ident(),每个(), 每一个(groovy.lang.Closure), count(), get(java.io.Serializable), print(java.lang.Object)

如果在控制器中调用这个事件一切都很好,并且这个插件的文档描述了我也可以在域模型和服务中调用事件......这个错误方法告诉我,该类不知道事件方法。

我还需要配置什么吗?

应该以其他方式调用事件还是我的错误在哪里?

有人体验过这个模块吗?

4

2 回答 2

3

The event(...) dynamic methods are not available on class (static) level.

You can pull the grailsEvents spring bean and call its event() method alternatively. You still have to get the bean from the application context statically though.

You could also use a custom validator instead, as you can get the current domain instance as a parameter, which should have the event() method injected.

something like this :

static myList = []
static constraints = {
    einrichtungs_type validator: { value, instance ->
        if(!myList){
            // cache it the first time you save/validate the domain
            // I would probably recommend you NOT to do this here though in 
            // real life scenario
            def reply = instance.event('blabla').get()
            myList = reply.value.toList()
        }

        return value in myList
    }
}

Anyway, In my case I would probably load the list elsewhere (in the Bootstrap.groovy for instance) and use it / inject it in my domain instead of doing in the constraints closure.

于 2013-05-29T13:38:21.207 回答
0

我遇到了类似的问题,我想在服务类中使用事件调用,该服务类将调用其他服务类中的侦听器。当我启动我的应用程序时,我遇到了同样的错误。我所做的是,在下面添加了 plugin( platform-core:1.0.RC5) 条目BuildConfig.groovy

plugins {

    build(":tomcat:$grailsVersion",
        ":platform-core:1.0.RC5") {
        export = false
    }
    compile ':platform-core:1.0.RC5'
    runtime ':platform-core:1.0.RC5'
}

然后我在该项目上运行 grails > clean 和 grails > compile 并重新启动服务器。它开始工作。可能你可以试一试。

于 2013-09-30T18:09:20.063 回答