How to use package name to distinguish classes in grails?

Can you use the package name to distinguish between classes in grails?

eg. com.business.appName.DomainClass and com.business.appName.foo.DomainClass?

I think this is causing problems since Grails needs unique class names. If you try this, it will try to overwrite the gsps view for com.business.appName.DomainClass when you try to generate views for com.business.appName.foo.DomainClass

Is there a way to have the same domain class name in different packages?

+2
grails
source share
2 answers

The problem is that the controller names must be unique. Running "generate-controller" or "generate-all" for two domain classes with the same name in different packages creates two different controllers each in its own package, but they will both appear in the URLs / yourapp / domainClass and the folder will be shared grails-app / views / domainClass GSP.

You will need to rename one of the controllers, since you cannot have two identical names even in different packages and cannot fix it even in URLs, so it would be better if you want to use the generated code to generate the first set and move the controller and look to the side, and then generate a second set. Then rename one or both of the controllers so that they have unique URLs and rename the corresponding GSP folders.

+3
source share

If your gsp has a problem, try declaring at the top

<%@ page import="com.thePackageIWant.TheClassIWant" %> 

Edit: Did you try to specify a package when creating views?

grails generate-views com.business.appName.foo.DomainClass

Sorry, I'm new to Grails, so I can no longer help you :(

0
source share

All Articles