Can grails controller move from base class? How to make the grail not explode?

I wrote a base class to quickly create my controllers and remove duplication. It provides some helper methods, default actions, and some metaprograms to make them easier to create.

One of these methods in the base class is as follows:

def dynamicList(Class clazz) { def model = new LinkedHashMap() model[getMapString(clazz) + "s"] = list(clazz) model[getMapString(clazz) + "sTotal"] = count(clazz) model } 

The action that invokes it, also in the base class, is as follows:

 def list = { dynamicList(clazz) } 

Unfortunately, when I go to the list of actions in a controller subclass that inherits the base class when deploying my application, I get this exception:

 groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException.dynamicList() is applicable for argument types: (java.lang.Class) values: [class project .user.User] at project.user.UserController$_closure1.doCall(UserController.groovy:18) at project.user.UserController$_closure1.doCall(UserController.groovy) at java.lang.Thread.run(Thread.java:619) 

How can I put gravel over my head and just say that he is doing what I want him to do? My tests on the controller work very well, so Grails runtime is completely to blame: /

Ken

+4
source share
3 answers

Are you sure that your inheritance is all right, and you run grails clean, etc.? The situation you described should work fine.

0
source

Is this all the code? You will probably have problems calling list() in dynamicList() , as it matches the action. In other words, list() is short for list.call() , which will cause the closure of list .

Of course, something very strange happens because the exception says that he cannot find the dynamicList() method in the MissingMethodException class.

Do you have a reproducible example?

0
source

I think the controllers run through the Grails implementation framework, so maybe this is not the best way to use the strange inheritance logic.

Although you can use composition instead of extending the base class. There is a function that makes it easy to enter services into controllers, so you can group by functionality into Services. enter the link here

This is an old question, you can find the answer or a little advanced technology.

Automatic injections for services and controllers and tag libraries.

0
source

Source: https://habr.com/ru/post/1311323/


All Articles