开发者

ArrayList and Map problem in grails

I have a service that contains a map:

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

that is returned via a method in the service:

 static Map getCargos() {
    [cargosMap]
 }

A controller calls it like this:

def mform = {

    Map cargos = empService.getCargos()

    [cargos:cargos]
}

In the gsp, I have the select:

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

But I'm getting the exception:

 Error 500: Executing action  ....caused exception: 
   org.codehaus.groovy.runtime.typehandling.GroovyCastException: Ca开发者_如何学Gonnot cast object
   ...  
   with class 'java.util.ArrayList' to class 
  'java.util.Map'

Any clues ? Thanks


Looks to me like you're wrapping the map in an ArrayList in getCargos(). Why not just: static getCargos() { cargosMap }. Or, better yet, just rename cargosMap to cargos and Groovy will create the getter for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜