tags:

views:

415

answers:

3

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.

<%@page import="path.to.domains.*"%>

Any help is appreciated.

Thank you.

+1  A: 

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.

John Wagenleitner
A: 

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

Fletch
A: 

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.

dbasta