grails question (sample 1 of Grails To Action book) problem with Controller and Service

Posted by fegloff on Stack Overflow See other posts from Stack Overflow or by fegloff
Published on 2010-06-16T21:44:42Z Indexed on 2010/06/16 21:52 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

Hi,

I'm doing Grails To Action sample for chapter one. Every was just fine until I started to work with Services. When I run the app I have the following error:

groovy.lang.MissingPropertyException: No such property: quoteService for class: qotd.QuoteController

at qotd.QuoteController$_closure3.doCall(QuoteController.groovy:14)

at qotd.QuoteController$_closure3.doCall(QuoteController.groovy)

at java.lang.Thread.run(Thread.java:619)

Here is my groovie QuoteService class, which has an error within the definition of GetStaticQuote (ERROR: Groovy:unable to resolve class Quote)

 package qotd

    class QuoteService {

 boolean transactional = false

 def getRandomQuote() {
  def allQuotes = Quote.list()
  def randomQuote = null
  if (allQuotes.size() > 0) {
   def randomIdx = new Random().nextInt(allQuotes.size())
   randomQuote = allQuotes[randomIdx]
  } else {
   randomQuote = getStaticQuote()
  }
  return randomQuote
 }

 def getStaticQuote() {
  return new Quote(author: "Anonymous",content: "Real Programmers Don't eat quiche")
 }
     }

Controller groovie class

package qotd

class QuoteController {

   def index = {
     redirect(action: random)
   }

   def home = {
     render "<h1>Real Programmers do not each quiche!</h1>" 
   }

  def random = {
     def randomQuote = quoteService.getRandomQuote()
     [ quote : randomQuote ]
   }

  def ajaxRandom = {
     def randomQuote = quoteService.getRandomQuote()
     render "<q>${randomQuote.content}</q>" +
     "<p>${randomQuote.author}</p>"
   }
}

Quote Class:

package qotd

class Quote {
   String content
   String author
   Date created = new Date()

   static constraints = {
     author(blank:false)
     content(maxSize:1000, blank:false) 
    }
}

I'm doing the samples using Eclipse with grails addin. Any advice?

Regards,

Francisco

© Stack Overflow or respective owner

Related posts about grails

Related posts about service