2010-04-12 50 views
0

我有一個包含地圖服務地圖問題:ArrayList和Grails中

static Map cargosMap = ['1':'item1','2':'item 2','3':'item 3'] 

是經由方法在服務返回:

static Map getCargos() { 
    [cargosMap] 
} 

控制器調用它是這樣的:

def mform = { 

    Map cargos = empService.getCargos() 

    [cargos:cargos] 
} 

在GSP,我有選擇:

<g:select name="cg1" from="${cargos}" /> 

但我發現了異常:

Error 500: Executing action ....caused exception: 
    org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 
    ... 
    with class 'java.util.ArrayList' to class 
    'java.util.Map' 

任何線索?謝謝

回答

3

在我看來,像你在包裝地圖的ArrayList getCargos()。爲什麼不只是:static getCargos() { cargosMap }。或者,更好的是,只需將cargosMap重命名爲cargos,Groovy將爲您創建getter。