Paul
Paul

Reputation: 2581

How to use the package name to differentiate between classes in grails?

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

e.g. com.business.appName.DomainClass and com.business.appName.foo.DomainClass?

I think that this causes problems as grails needs unique class names. If you try this out it tries to overwrite the view gsps for the com.business.appName.DomainClass when you try to generate the views for the com.business.appName.foo.DomainClass

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

Upvotes: 2

Views: 1118

Answers (2)

Burt Beckwith
Burt Beckwith

Reputation: 75671

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

You'll need to rename one of the controllers anyway since you can't have two with the same name even in different packages and can't fix this even in URLMappings, so it looks like your best bet if you want to use the generated code is to generate the first set and move the controller and views out of the way, then generate the second set. Then rename one or both of the controllers so they'll have unique URLs and rename the corresponding GSP folders.

Upvotes: 3

ccheneson
ccheneson

Reputation: 49410

If there is problem in your gsp, try by declaring at the top

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

Edit: Have you tried to specify the package when generating views?

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

Sorry, I am a newbie in Grails so I may not be able to help you more :(

Upvotes: 0

Related Questions