|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Where did my dynamic methods go?I've been scratching my head on this one for a while, here is the thing, I have added a new dynamic method with a custom plugin like so
def doWithDynamicMethods = { ctx -> // TODO Implement registering dynamic methods to classes (optional) application.controllerClasses.each { controllerClass -> LOG.info("Adding gfx capabilities to ${controllerClass.clazz.name}") controllerClass.metaClass.renderImage = { Map props, Closure cls -> Gfx.renderImage( delegate.response, props, cls ) } } } calling a sample Controller with the app running works, but if the controller source is updated in any way then the dynamic methods are gone and a bug fat exception is shown =( Here is the output from grails console before and after the source has been updated (a simple file -> save is enough to trigger this!) ------- snip -------- groovy> def ms = ProjectController.metaClass.methods.name groovy> ms.sort() Result: ["bindData", "bindData", "bindData", "bindData", "bindData", "bindData", "chain", "equals", "getActionName", "getActionUri", "getAllowedMethods", "getChainModel", "getClass", "getControllerName", "getControllerUri", "getCreate", "getDelete", "getEdit", "getErrors", "getFlash", "getG", "getGrailsApplication", "getGrailsAttributes", "getGraph", "getIndex", "getList", "getLog", "getMetaClass", "getModelAndView", "getParams", "getPluginContextPath", "getProperty", "getRequest", "getResponse", "getSave", "getServletContext", "getSession", "getShow", "getTemplateUri", "getUpdate", "getViewUri", "hasErrors", "hashCode", "header", "invokeMethod", "jsonHeader", "methodMissing", "notify", "notifyAll", "redirect", "render", "render", "render", "render", "render", "render", "renderImage", "setAllowedMethods", "setCreate", "setDelete", "setEdit", "setErrors", "setGraph", "setIndex", "setList", "setMetaClass", "setModelAndView", "setProperty", "setSave", "setShow", "setUpdate", "toString", "wait", "wait", "wait", "withFormat"] /* update ProjectController.groovy and save it */ groovy> def ms = ProjectController.metaClass.methods.name groovy> ms.sort() Result: ["asType", "decodeBase64", "decodeHTML", "decodeJSON", "decodeJavaScript", "decodeURL", "decodeXML", "encodeAsBase64", "encodeAsHTML", "encodeAsJSON", "encodeAsJavaScript", "encodeAsURL", "encodeAsXML", "equals", "getAllowedMethods", "getClass", "getCreate", "getDelete", "getEdit", "getGraph", "getIndex", "getList", "getMetaClass", "getProperty", "getSave", "getShow", "getUpdate", "hashCode", "invokeMethod", "notify", "notifyAll", "setAllowedMethods", "setCreate", "setDelete", "setEdit", "setGraph", "setIndex", "setList", "setMetaClass", "setProperty", "setSave", "setShow", "setUpdate", "toString", "wait", "wait", "wait"] ------- snip -------- now all render* methods are gone! (among others) grails 1.0.3java version "1.6.0_10-beta" Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b23) Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing) Perhaps the answer lies just in front of my eyes but can't see it. I'll appreciate any pointers on this matter, thanks! |
|
|
Re: Where did my dynamic methods go?> now all render* methods are gone! (among others)
You need to re-add them in the "onChange" closure, which usually means factoring out the dynamic methods into a separate method called from "doWithDynamicMethods" and "onChange". Here's an example: http://svn.grails-plugins.codehaus.org/browse/grails-plugins/grails-jsecurity/trunk/JsecurityGrailsPlugin.groovy?r=42043 Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Where did my dynamic methods go?Thanks Peter, I figured that something was the solution.
Question, why do we need to re-add them in the first place? shouldn't this be automatically handled by the framework? perhaps there is something I'm missing here
|
| Free Forum Powered by Nabble | Forum Help |