开发者

ArrayList and Map problem in grails

开发者 https://www.devze.com 2022-12-26 07:04 出处:网络
I have a service that contains a map: static Map cargosMap = [\'1\':\'item1\',\'2\':\'item 2\',\'3\':\'item 3\']

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

精彩评论

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