-
Notifications
You must be signed in to change notification settings - Fork 952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.1.1] Parent class methods are not registered as controller actions #9731
Comments
I think you can also work around it by making the parent class non-abstract. We will take a look and get it straightened out. Thanks! |
@jeffbrown I just did quick check. For parent class in Thank you for the support |
I wouldn't expect it to work under The existence of a controller should not create any endpoints at all. I don't understand that. URL mappings result in endpoints. |
This is what I meant. Thinking that default new application and probably most of existing ones will have some 'universal' url mapping with |
@droggo Is it your request that if a controller extends an abstract class that is defined under |
Yes, this is how it was working in Grails 2. Because If this is not possible because of Grails 3 architecture, annotating methods with |
I don't think it is the case that it is not possible. We just need to agree on desired behavior and then we can make it so. :) |
@droggo @jeffbrown I think having to mark the methods with |
@Schlogen I have mixed feelings. From one point of view, you have to decide that this is action, and it's more secure, from other we break convention and go back to annotations... @jeffbrown Maybe also traits should be considered? Here may be the issue that a lot of Core traits are used and those already add public methods which are not and should not be actions. But I've already seen few questions on Slack about adding controller methods with traits |
if you have a class in |
We don't want to add controllers from |
But that is not true, you're adding actions, that isn't a common method :) |
Sorry for my english. By common I meant controller actions which will be the same in multiple controllers and to not copy/paste code and keep it DRY, super class could be used. For example generated controllers containing show/update/save actions are nearly the same. We just created superclass which delivers all those methods. Controllers extending this class only defines entity which is handled. |
Sure, but that super class is a controller, and for Grails to treat it us such it needs to compile it as such. The only way it can know to compile the class as a controller is if you annotate it with |
Here's the summary after a discussion on Slack - https://grails.slack.com/archives/questions/p1456394917001749 It is not supported by Grails 3 to add controller actions through inheritance (abstract class, trait, super class) unless class is marked with @controller or is a controllers from Working approach is to create standard controller in This is also related to abstract domain classes - grails/grails-data-mapping#639 |
Hi droggo Sorry for digging out this already closed issue, I'm not even sure if anybody is notified about my comment. I have tried to implement something similar like you, I want to abstract some of the methods that are very similar in most of the controller, like create/save/edit/update/delete. I already achived it to inherit actions from a base controller class, but i'm not able to create or save any entity. Normally a action look something like this (simplified):
Now the method must be changed to something dynamic that is not fixed on a concrete domain class. I already tried to use a template class but it did not work :( You wrote:
How did you do that? |
@anderskristian you use generics, look at RestFulController for example |
So we have an abstract BaseCrudController which is in /src/main/groovy - it is very similar to RestFulController, and provides CRUD actions (create/edit/save/update/delete/list) Putting the @ArteFact("Controller") annotation on the class BaseCrudController seem to solve the issue and the actions are available to subclasses. So, BookController extends BaseCrudController and all CRUD actions are available to Book controller. So looks like the @ArteFact("Controller") is the solution |
After migration from 2.5.2 to 3.1.1, methods defined in abstract parent class are not recognized as controller actions. It doesn't matter if file is defined in
grails-app/controllers
orsrc/main
.It may be worked around using
@grails.web.Action
annotation on methods which should be actions. But this will not work if action has any parameters defined.So:
Will return 404 on
specific/a
request.Will render
a
as request response - which is fine.Will throw exception during application start:
It can be solved creating two methods in abstract class and manually calling desired method.
Two issues with this approach are:
Is this a bug?
Is there a way to create required action method without parameters using existing Grails classes?
The text was updated successfully, but these errors were encountered: