How do you share common methods in different grails controllers? -


currently when need share method processparams(params) between different controllers, use either inheritance or services. both solution has inconvenients :

  • with inheritance, cannot use multiple inheritance means need have of controller utility methods in 1 place. , also, there bug in grails not detect code changes in base controller classes in development mode (you need restart app)
  • with services, don't have access injected properties params, session, flush...

so question : there other way use common methods accessible multiple controllers ?

one option write common methods category, mix controllers necessary. gives lot more flexibility inheritance, has access stuff params, , code simple , understandable.

here's tiny example:

@category(object) class mycontrollercategory {     def printparams() {         println params     } }  @mixin(mycontrollercategory) class somethingcontroller {      def create = {         printparams()         ...     }      def save = {         printparams()     } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -