FANDOM


  • Create the domain class Contact.groovy
package com.rtt

class Contact implements Serializable {
    String firstName
    String lastName
    String address1
    String address2
    String city
    String state
    String zip
    String phone
    String email

    static constraints = {
        firstName(blank:false, nullable:false, maxSize: 50)
        lastName(blank:false, nullable:false, maxSize: 50)
        address1(blank:false, nullable:false, maxSize: 50)
        address2(blank:true, nullable:true)
        city(blank:false, nullable:false, maxSize: 50)
        state(blank:false, nullable:false, maxSize: 2)
        zip(blank:false, nullable:false, maxSize: 10)
        phone(blank:false, nullable:false, maxSize: 15)
        email(blank:false, nullable:false, maxSize: 50)
    }
    
    String toString() {
        "${firstName} ${lastName}"
    }
}
  • Create the controller ContactController.groovy
package com.rtt

class ContactController {
    def scaffold = true

    def transient sessionFactory

    def buildFlow = {
        enter {
            action {
                Contact flow.contact = new Contact()
                [contact: flow.contact]
            }
            on("success").to("name")
            on(Exception).to("error")
        }
        name { 
            on('next') { BuildContactNameCommand command ->
                if (command.hasErrors()) {
                    flash.message = "Validation error"
                    flow.command = command
                    return error()
                }
                bindData(flow.contact, command)
                [contact: flow.contact]
            }.to('address')
            on('cancel').to('finish')
        }
        address { 
            on('next') { BuildContactAddressCommand command ->
                if (command.hasErrors()) {
                    flash.message = "Validation error"
                    flow.command = command
                    return error()
                }
                bindData(flow.contact, command)
                [contact: flow.contact]
            }.to('electronic')
            on('previous').to('name')
            on('cancel').to('finish')
        }
        electronic { 
            on('next') { BuildContactElectronicCommand command ->
                if (command.hasErrors()) {
                    flash.message = "Validation error"
                    flow.command = command
                    return error()
                }
                bindData(flow.contact, command)
                [contact: flow.contact]
            }.to('complete')
            on('previous').to('address')
            on('cancel').to('finish')
        }   
        complete {
            on('next') {
                if (!flow.contact.save()) {
                    flash.message = "Couldn't save the contact"
                    return error()
                }
            }.to('finish')
            on('previous').to('electronic')
            on('cancel').to('finish')
            on(Exception).to('error')
        }
        error {
            on('confirm').to('finish')
        }   
        finish {
            redirect(controller: 'contact', action: 'list')
        }
    }
    
}

class BuildContactNameCommand implements Serializable {
    String firstName
    String lastName

    static constraints = {
        firstName(blank:false, nullable:false, maxSize: 50)
        lastName(blank:false, nullable:false, maxSize: 50)
    }

}

class BuildContactAddressCommand implements Serializable {
    String address1
    String address2
    String city
    String state
    String zip

    static constraints = {
        address1(blank:false, nullable:false, maxSize: 50)
        address2(blank:true, nullable:true)
        city(blank:false, nullable:false, maxSize: 50)
        state(blank:false, nullable:false, maxSize: 2)
        zip(blank:false, nullable:false, maxSize: 10)
    }

}

class BuildContactElectronicCommand implements Serializable {
    String phone
    String email

    static constraints = {
        phone(blank:false, nullable:false, maxSize: 15)
        email(blank:false, nullable:false, maxSize: 50)
    }

}
  • Create the view address.gsp
<html>
<head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Build Contact - Address</title>
</head>
<body>
    <div class="body">
        <h1>Build Contact - Address</h1>
        <g:if test="${message}">
            <div class="message">${message}</div>
        </g:if>
        <g:hasErrors bean="${command}">
            <div class="errors">
                <g:renderErrors bean="${command}" as="list" />
            </div>
        </g:hasErrors>
        <g:form action="build">
            <div class="dialog">
                <table>
                <tbody>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="address1">Address 1:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="address1" name="address1" value="${contact.address1}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="address2">Address 2:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="address2" name="address2" value="${contact.address2}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="city">City:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="city" name="city" value="${contact.city}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="state">State:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="state" name="state" value="${contact.state}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="zip">
                            <label for="zip">ZIP:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="zip" name="zip" value="${contact.zip}" />
                        </td>
                    </tr>
                </tbody>
                </table>
            </div>
            <div class="buttons">
                <span class="button">
                    <g:submitButton class="previous" name="previous" value="Previous" />
                    <g:submitButton class="next" name="next" value="Next" />
                    <g:submitButton class="cancel" name="cancel" value="Cancel" />
                </span>
            </div>
        </g:form>
    </div>
</body>
</html>
  • Create the view complete.gsp
<html>
<head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Build Contact - Complete</title>
</head>
<body>
    <div class="body">
        <h1>Build Contact - Complete</h1>
        <g:if test="${message}">
            <div class="message">${message}</div>
        </g:if>
        <g:form action="build">
            <div class="dialog">
                <table>
                <tbody>
                    <tr class="prop">
                        <td valign="top" class="name">First Name:</td>
                        <td valign="top" class="value">${contact.firstName}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">Last Name:</td>
                        <td valign="top" class="value">${contact.lastName}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">Address 1:</td>
                        <td valign="top" class="value">${contact.address1}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">Address 2:</td>
                        <td valign="top" class="value">${contact.address2}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">City:</td>
                        <td valign="top" class="value">${contact.city}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">State:</td>
                        <td valign="top" class="value">${contact.state}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">ZIP:</td>
                        <td valign="top" class="value">${contact.zip}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">Phone:</td>
                        <td valign="top" class="value">${contact.phone}</td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">Email:</td>
                        <td valign="top" class="value">${contact.email}</td>
                    </tr>
                </tbody>
                </table>
            </div>
            <div class="buttons">
                <span class="button">
                    <g:submitButton class="previous" name="previous" value="Previous" />
                    <g:submitButton class="next" name="next" value="Finish" />
                    <g:submitButton class="cancel" name="cancel" value="Cancel" />
                </span>
            </div>
        </g:form>
    </div>
</body>
</html>
  • Create the view electronic.gsp
<html>
<head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Build Contact - Electronic</title>
</head>
<body>
    <div class="body">
        <h1>Build Contact - Electronic</h1>
        <g:if test="${message}">
            <div class="message">${message}</div>
        </g:if>
        <g:hasErrors bean="${command}">
            <div class="errors">
                <g:renderErrors bean="${command}" as="list" />
            </div>
        </g:hasErrors>
        <g:form action="build">
            <div class="dialog">
                <table>
                <tbody>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="phone">Phone:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="phone" name="phone" value="${contact.phone}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="email">Email:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="email" name="email" value="${contact.email}" />
                        </td>
                    </tr>
                </tbody>
                </table>
            </div>
            <div class="buttons">
                <span class="button">
                    <g:submitButton class="previous" name="previous" value="Previous" />
                    <g:submitButton class="next" name="next" value="Next" />
                    <g:submitButton class="cancel" name="cancel" value="Cancel" />
                </span>
            </div>
        </g:form>
    </div>
</body>
</html>
  • Create the view error.gsp
<html>
<head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Build Contact - Error</title>
</head>
<body>
    <div class="body">
        <h1>Build Contact - Error</h1>
        <g:if test="${message}">
            <div class="message">${message}</div>
        </g:if>
        <g:form action="build">
            <div class="dialog">
                <p>Sorry, but the system has reported an unrecoverable error.</p>
            </div>
            <div class="buttons">
                <span class="button">
                    <g:submitButton class="confirm" name="confirm" value="OK" />
                </span>
            </div>
        </g:form>
    </div>
</body>
</html>
  • Create the view name.gsp
<html>
<head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Build Contact - Names</title>
</head>
<body>
    <div class="body">
        <h1>Build Contact - Name</h1>
        <g:if test="${message}">
            <div class="message">${message}</div>
        </g:if>
        <g:hasErrors bean="${command}">
            <div class="errors">
                <g:renderErrors bean="${command}" as="list" />
            </div>
        </g:hasErrors>
        <g:form action="build">
            <div class="dialog">
                <table>
                <tbody>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="firstName">First Name:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="firstName" name="firstName" value="${contact.firstName}" />
                        </td>
                    </tr>
                    <tr class="prop">
                        <td valign="top" class="name">
                            <label for="lastName">Last Name:</label>
                        </td>
                        <td valign="top">
                            <input type="text" id="lastName" name="lastName" value="${contact.lastName}" />
                        </td>
                    </tr>
                </tbody>
                </table>
            </div>
            <div class="buttons">
                <span class="button">
                    <g:submitButton class="next" name="next" value="Next" />
                    <g:submitButton class="cancel" name="cancel" value="Cancel" />
                </span>
            </div>
        </g:form>
    </div>
</body>
</html>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.