How does Grails resolve controller name conflicts?

What is the recommended approach when the name of the application controller conflicts with the name of the plugin controller?

I saw these JIRA Grails: GRAILS-4240 GRAILS-1243

... and Burt Beckwith responds to these two streams, implies that the only way is to rename one of the controllers (presumably the application controller, since the cracked plug-in code is undesirable)

How to use a package name to differentiate classes in a graph?

How to extend / redefine plugin controller actions?

However, Burt's own spring-security-ui plugin advocates for an exact approach to assigning a Controller application in the same way as a plug-in controller - see spring-security-ui docs .

This approach really works both in development mode (grails run-app) and when the application is deployed as a WAR. So you can rely on this functionality? If so, what is the rule for resolving controller conflict? The Grail does not mention this. Can Perhasp Burt share his understanding?

Having a plug-in architecture like grails ", even without a base namespace for handling conflicts like this, seems very unpleasant to me ...

+4
grails
source share
1 answer

The problem is that although you can use packages for any artifact, the convention for controllers is to remove the package and the โ€œControllerโ€ to create URLs, for example. PersonController -> / appname / person / action_name. Thus, as a result, everything is smoothed out.

In 1.2 and more, so 1.3 has changed, so the plugins are compiled separately from the application code (and compiled in the first place), and this gives you the opportunity to replace the plugin artifact with the version of the application. Since you do not have to edit the plugin code, this gives you the opportunity to extend or replace the plugin artifact using the same name.

I usually use UrlMappings to get around this when there are two similarly named controllers. For example, you have a UserController administrator who allows you to perform low-level CRUD actions and the usual UserController that users work with. I would call the administrator AdminUserController and map it to / admin / user / * and leave UserController as it is. The administrator GSP will be in views / adminUser, and the rest will be in views / users so that there are no conflicts. This has the additional advantage of being able to easily protect - map / admin / ** โ†’ ROLE_ADMIN. The conventions are convenient, but this is a simple configuration step that solves this problem for me.

The good news is that the GRAILS-1243 will definitely be implemented in version 2.0 and possibly version 1.4. And the plugin quoted by Kim Betty in the comments of GRAILS-1243 looks interesting.

+6
source share

All Articles