views:

180

answers:

1

Hi, 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: Cannot cast object
   ...  
   with class 'java.util.ArrayList' to class 
  'java.util.Map'

Any clues ? Thanks

+3  A: 

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.

ig0774