views:

36

answers:

1

I have a controller and a gsp. I go ahead and attempt to build the project but receive issues on my gsp.

It is telling me "The current scope already contains a variable of the name it"

<html>
  <head>
    <title>Book Collector</title>
    <meta name="layout" content="main" />
  </head>
  <body>
    <h1>Book Editor</h1>
    <table>
      <tr>
        <th>Book Name</th>
        <th>Author</th>
        <th>Page Number</th>
        <th>Vendor</th>
        <th>Date Scanned</th>
        <th>Date Read</th>
      </tr>
      <% bookList.each { it -> %>
      <tr>
        <td><%= it.bookName %></td>    //this is where the error starts
        <td><%= it.author %></td>      //error (it)
        <td><%= it.pageNumber %></td>  //error (it)
        <td><%= it.lastScan %></td>    //error (it)
        <td><%= it.lastRead %></td>    //error (it)
        <% } %>
      </tr>
    </table>
  </body>
</html>

Am I not allowed to use 'it' like that? Or is there something obvious that I'm missing?

+2  A: 

http://www.grails.org/Views+and+Layouts

<html>
<head>
    <title>Book list</title>
</head>
<body>
<h1>Book list</h1>
<table>
    <tr>
        <th>Title</th>
         <th>Author</th>
    </tr>
    <g:each in="${books}">
        <tr>
             <td>${it.title}</td>
             <td>${it.author}</td>
        </tr>
    </g:each>
</table>
</body>
</html>
Aaron Saunders
Thank you for the very quick response. I'll do some more reading. Could you give me a brief explanation why something like: <% bookList.each { it -> %> doesn't work? There is some information in the bookList that I don't need which is why I chose to iterate through and grab what I wanted. I bought the book Groovy Recipes to kind of learn from but the author assumes basic knowledge. (I have been reading a bit of grails in the mean time)
StartingGroovy
Aaron Saunders
The solution provided allows you to just pick out what you need... also I believe "it" is there by default... Please mark answer as correct if it was helpful, it will encourage more people to respond to your questions. There is a wealth of knowledge in StackOverflow so it is best to search here before posting a question
Aaron Saunders
Thank you Aaron, any recommended books for Groovy? (Groovy Recipes does a pretty good job, but doesn't cover everything)
StartingGroovy
Groovy In Action and http://groovy.codehaus.org/, TONS of examples here
Aaron Saunders
The first edition of Groovy in Action was a great book, but is now dangerously out-of-date. I would wait for the 2nd edition. I think it's currently available as an e-book in "beta" format.
Don
Thank you Don, I will go ahead and wait for the second edition. I've added all three books on the 'to-get' list.
StartingGroovy