groovy - How to access controller dynamic properties within a base controller's constructor in Grails? -
Actually, I want to be able to employ members in a base controller to design an object created within the filter, in which From each controller is extended. Any possible way to do this?
How I tried here, but did not get it to work.
What am I trying to achieve, expanding all of my controllers? The constructor of a base controller base controller will be used to provide value to its members, those values should be Sessions will be pulled from the map. . Example below
File grails-app / controller / HomeController.groovy:
class HomeController BaseController extends {render def index = {username}}
< / Pre - << p> file grails-app / controller / BaseController.groovy:abstract class BaseController {public string username public BaseController () {username = session.username}}
While running the app, the output shown is:
2010-06-15 18:17 17: 16,671 [main] error [localhost]. [/ Webapp] - exception model starts to tell listeners to send class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener org.springframework.beans.factory.BeanCreationException event: creating bean with name 'in pluginManager' ServletContext resources Defined [/ web-INF error / ApplicationContext.xml]: invocation of init method failed; Nested exception java.lang.RuntimeException is: java.lang.RuntimeException: Because of detection manufacturer with org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass orbit parameters for class ... unable class class parameters with unable to find the manufacturer org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass ... because: java.lang.reflect.InvocationTargetException ... due to: org.codehaus.groovy.grails.exceptions.NewInstanceCreationException : Could not create a new instance of the class [com.my.package.controller.HomeController]! Groovy.lang.MissingPropertyException: ... due to such a property: session to class. Com com.my.package.controller.HomeController at lt com.my.package.controller.basecontroller and; Init & gt; (BaseController.groovy: 16) at com.my.package.controller.HomeController & lt; Init & gt; (HomeController.groovy) ... 2010-06-15 18:. 17: 16,687 [main] error core.StandardContext - error listenerStart 2010-06-15 18: 17: 16,687 [main] error Korkstardcontekst - context [/ Vebppan] startup due to previous errors, failed
More apps will not run.
This is just an example of my example that I do not want to assign a username to string value, rather drag certain objects from the session map. Setting the session removed from the map are being set within the object filter.
The option I am looking at is capable of reaching the instance of the controller within the execution of the filter. Is this possible?
Please help! Thanks bunch!
You can usually do a lot in Grails artifacts in the manufacturer. You can use an interceptor for this:
Abstract class bas controller {protected string username username DRD before {0} =
It is described in Section 6.1.5 of
Comments
Post a Comment