Grails using a package to hold domain classes

Tag: grails Author: wljfena Date: 2009-08-04

Grails question: Confused about using a package to hold domain classes.

I'm using Netbeans on Mac to check out Grails.

When I create domain classes without using a package holding it, I can just go to localhost:8080/gTunes and the expected .gsp page is rendered properly.

However when I use a package (com.g2one.gtunes) to hold a domain class (Song), I don't see the .gsp page when I go to localhost:8080/gTunes. Instead I see a Directory view of folders/files such as META-INF, WEB-INF, etc. In order to see the expected .gsp page, I have to type in the specific URL localhost:8080/gTunes/index.gsp

In my research I've seen people talk about adding the following line but I can't figure out where to add it.

<[email protected] import="*"%>

Any help is appreciated.

Thank you.

consider using packages and when you create the controller, use com.g2one.gtunes.Song and the import will be added for you for you.

Other Answer1

You need to add that import to the top of your GSP pages that use the domain class that you put in a package. Don't forget you'll also need an import in your controllers unless that are in the same package.

Other Answer2

Add the specified line as the very first line in the GSP you are trying to render (show).

Other Answer3

Figured out why I way I was having this issue. I'm going through Definitive Guide to Grails 2nd Edt on mac with NetBeans. I ran into this problem when I

  • created 'gtunes' project at /Users/name/NetBeans/gtunes
  • deleted 'gtunes' project and /Users/name/NetBeans/gtunes
  • created another project with same name at /Users/name/NetBeans/gtunes. I type in some code and run it and I run into the error I posted.

To get around this error,

  • I create 'gtunes' project located at /Users/name/NetBeans/gtunes
  • I right click on 'gtunes' project in NetBeans, issue 'Clean' command. Than I see some files are removed from ~/.grails/... in Output window
  • I right click on Album.groovy (possibly Song.groovy also) and issue 'Generate Views', NOT 'Generate All'
  • Run the project and it works!

Thanks all for comments and hopefully my mistake will help others avoid same mistake.