gorm - Grails 3 - Add dynamic method from plugin using traits - not working -
i followed user guide add dynamic method controllers using trait plugin.
the following code:
---trait---
package com.ylw.gorm trait datetrait { date currentdate() { return new date() } }
---traitinjector---
package com.ylw.gorm import grails.compiler.traits.traitinjector import groovy.transform.compilestatic @compilestatic class controllertraitinjector implements traitinjector { @override class gettrait() { datetrait } @override string[] getartefacttypes() { ['controller'] string[] } }
---controller---
@transactional(readonly = true) class mydomaincontroller { static allowedmethods = [save: "post", update: "put", delete: "delete"] def testtrait() { render "the current date -> " + currentdate() } ... }
i expecting controller know currentdate() method trait. got following error in browser:
caused missingmethodexception: no signature of method: com.ylw.gorm.mydomaincontroller.currentdate() applicable argument types: () values: [] possible solutions: create() 90 | methodmissing in grails.artefact.gsp.taglibraryinvoker$trait$helper - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12 | $tt__testtrait in com.ylw.gorm.envers.auditeddomaincontroller 93 | dointransaction in grails.transaction.grailstransactiontemplate$2 90 | execute in grails.transaction.grailstransactiontemplate 1145 | runworker in java.util.concurrent.threadpoolexecutor 615 | run in java.util.concurrent.threadpoolexecutor$worker 745 | run . . . in java.lang.thread
what did wrong?
thanks help! yingliang
you haven't shown enough code sure going wrong.
i have created demo app @ https://github.com/jeffbrown/traitplugin.
see following:
those copied , pasted example code.
the app has controller @ following:
all of appears work.
ensure app has compile time dependency on plugin.
Comments
Post a Comment