|
I can call cookie() in a controller, but when I call it in a service, I got the following error message:
Error 500: Executing action [list] of controller [app.NameController] caused exception: groovy.lang.MissingMethodException: No signature of method: app.SearchService.cookie() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:Ticket]] Servlet: grails URI: /app/grails/lead/list.dispatch Exception Message: No signature of method: app.SearchService.cookie() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:Ticket]] Caused by: No signature of method: app.SearchService.cookie() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:Ticket]] Class: NameController I need to call a method in many controllers and that method calls cookie(), so I would like to implement that method in a service in stead of in every controller. Thanks for any help. |
|
cookie is on the request, there is a source link in the docs for the cookie tag. That is what you are calling when you do call cookie() in the controller
you should consider creating your own special tag if its used all over the place. If you really decide a service is the right place then use RequestContextHolder.requestAttributes.request to get at the request On Jan 20, 2012, at 7:34 AM, spz1st wrote: > I can call cookie() in a controller, but when I call it in a service, I got > the following error message: > > Error 500: Executing action [list] of controller [app.NameController] caused > exception: groovy.lang.MissingMethodException: No signature of method: > app.SearchService.cookie() is applicable for argument types: > (java.util.LinkedHashMap) values: [[name:Ticket]] > Servlet: grails > URI: /app/grails/lead/list.dispatch > Exception Message: No signature of method: app.SearchService.cookie() is > applicable for argument types: (java.util.LinkedHashMap) values: > [[name:Ticket]] > Caused by: No signature of method: app.SearchService.cookie() is applicable > for argument types: (java.util.LinkedHashMap) values: [[name:Ticket]] > Class: NameController > > I need to call a method in many controllers and that method calls cookie(), > so I would like to implement that method in a service in stead of in every > controller. > > Thanks for any help. > > > -- > View this message in context: http://grails.1312388.n4.nabble.com/cookie-availe-in-controller-but-not-in-service-tp4313241p4313241.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thanks. But I don't know how to use it. When I tried
RequestContextHolder.requestAttributes.request.cookie() in a service, I got the following error: groovy.lang.MissingPropertyException: No such property: RequestContextHolder for class: app.SearchService |
|
RequestContextHolder is a spring helper class.
getRequestAttributes returns a GrailsWebRequest which extends springs DispatcherWebRequest (or something like that) google for the packages to import and the javaDocs for the details On Jan 20, 2012, at 2:53 PM, spz1st wrote: > Thanks. But I don't know how to use it. When I tried > RequestContextHolder.requestAttributes.request.cookie() in a service, I got > the following error: > > groovy.lang.MissingPropertyException: No such property: RequestContextHolder > for class: app.SearchService > > > -- > View this message in context: http://grails.1312388.n4.nabble.com/cookie-availe-in-controller-but-not-in-service-tp4313241p4314453.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by spz1st
Can't you just pass the cookie value (or cookie instance) from the controller to the service?
Accessing a cookie from a service sounds like bad design to me. Regards /Goran Ehrsson 20 jan 2012 kl. 21:53 skrev spz1st:
|
| Powered by Nabble | Edit this page |
