Question

I am quite new to Grails and Groovy and found strange behaviour. In one of my controller classes I have following list() method:

def list() {
    [priceListInstanceList: PriceList.list(), priceListInstanceTotal: PriceList.count()]
}

and when I am calling this from my gsp g:select everything works fine:

<g:select name="priceListId" from="${vladar.PriceList.list()}" optionKey="id" optionValue="priceListName" />

Now if I will make a new method exactly the same like list() and change the name to list2()

def list2() {
    [priceListInstanceList: PriceList.list(), priceListInstanceTotal: PriceList.count()]
}

and change g:select accordingly:

<g:select name="priceListId" from="${vladar.PriceList.list2()}" optionKey="id" optionValue="priceListName" />

I have get an error message:

Class 
groovy.lang.MissingMethodException

Message
No signature of method: vladar.PriceList.list2() is applicable for argument types: () values: [] Possible solutions: list(), list(java.util.Map), last(), last(java.lang.String), last(java.util.Map), first()

It looks like there is some magic with list() method under the hood. I want to get a specific options in g:select. I wrote controller part which render just fine but when I am trying to return values to gsp get the same message. It seems it is general problem not with my controller. Any ideas how to fix list2 so it will show in g:select? Thank you.

Was it helpful?

Solution

You have method list2() in your controller, not in your PriceList domain.

${vladar.PriceList.list()} means: call method 'list' from class 'PriceList'.

Seems that you misunderstand MVC conception, and how it's used in Grails. You have to prepare all data in controller, and pass to the view.

For your situation PriceListController.list() is action for url /priceList/list. Controller should load all data from db (call PriceList.list() inside action-method list) and GSP have to prepare html from this data (<g:select from="${priceListInstanceList}")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top