2013-05-14 24 views
1

我嘗試使用platform-core-1.0 rc5插件來按事件服務。現在,我在grails-插件「listadmin」寫一個服務:grails 2.2.2 platform-core-plugin在域模型中沒有方法事件的簽名

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

如果我嘗試運行此應用程序,我得到以下錯誤:

Caused by MissingMethodException: No signature of method: institutionadmin.Einrichtung.event() is applicable for argument types: (java.util.LinkedHashMap) values: [[for:listadmin, topic:testEventBus]] Possible solutions: ident(), every(), every(groovy.lang.Closure), count(), get(java.io.Serializable), print(java.lang.Object)

如果調用此事件的控制器一切都很好這個插件的文件描述了我也呼籲事件域模型和服務......這種錯誤的方法告訴我,這個類不知道事件的方法。

我一定要配置什麼嗎?

應該以其他方式致電活動或我的錯誤在哪裏?

有沒有人有這個模塊出現?

回答

3

event(...)動態方法在類(靜態)級別上不可用。

您可以拉grailsEvents春豆,並調用其event()方法。你仍然需要靜態地從應用程序上下文獲取bean。

您也可以改爲使用自定義驗證器,因爲您可以將當前域實例作爲參數應用,該參數應注入event()方法。

是這樣的:

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

反正對我來說,我可能會加載列表中的其他地方(在Bootstrap.groovy爲例),並用它/注入在我的領域,而不是在限制閉合做。

0

我遇到過類似的問題,我想用一個服務類中的事件調用來調用其他服務類中的監聽器。當我開始我的應用我有我做的是同樣的error.What,添加插件(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>清潔和Grails>編制有關該項目並重新啓動它開始工作。可能是你可以試試。

相關問題