Learn Java for Web Development

(Tina Meador) #1

340 CHAPTER 7: Rapid Web Development with Grails


40.${fieldValue(bean: bookInstance, field: "price")}
41.
42.${fieldValue(bean: bookInstance, field: "isbn")}
43.
44.
45.</g:each>
46.
47.
48.


51.

52.
53.


   Line 14: The <g:link> tag creates a link to the create action of the
BookController.
 Line 19: The <g:if> tag checks for the existence of flash.message that was
stored in the action and, if found, displays it.
 Lines 26 to 31: The <g:sortableColumn> tag is used to provide sorting on our
list view.
 Lines 35 to 45: The <g:each> tag iterates over the bookInstanceList. Each item
in the list is assigned to the bookInstance variable. The body of the <g:each>
tag fills in the table row with the properties of the bookInstance. In the line
<tr class="${(i % 2) == 0? 'even' : 'odd'}">, a Groovy expression is used
to determine the style class of the <tr>, and the fieldValue( ) method is used
to render the value of each Book property.
 Line 49: The <g:paginate> tag displays the pagination controls if there are
enough elements in the list view. The bookInstanceTotal is used from
Listing 7-19, as mentioned earlier.

The Create View


The create view is illustrated in Listing 7-28.


Listing 7-28. create.gsp


1.<%@ page import="bookstore.Book" %>
2.<!DOCTYPE html>
3.
4.
5.
6.
7.<g:message code="default.create.label" args="[entityName]" />
8.
9.
10.

Free download pdf