Learn Java for Web Development

(Tina Meador) #1
CHAPTER 7: Rapid Web Development with Grails 343

43.
44.


  • 45.<g:message code="book.isbn.label"
    default="Isbn" />

    46.
    47.<g:fieldValue bean="${bookInstance}"
    field="isbn"/>

    48.
    49.

  • 50.</g:if>
    51.
    52.
    53.
    54.

    55.
    56.<g:message
    code="default.button.edit.label" default="Edit" /></g:link>
    57.
    58.

    59.</g:form>
    60.

    61.
    62.


       Lines 55 to 56: The? after the bookInstance reference is a safe navigation
    operator. When this expression is evaluated and if bookInstance is null, the
    whole expression evaluates to null, and no exception is thrown.
     Line 57: The <g:actionSubmit> tag generates a submit button that maps to a
    specific action, which lets you have multiple submit buttons in a single form.
    JavaScript event handlers can be added using the same parameter names as in
    HTML.

    The Edit View


    The edit view is illustrated in Listing 7-30.


    Listing 7-30. edit.gsp


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

    Free download pdf