Question

I am new to Grails development. I started doing the web flow for the user registration. It has two forms that in first form i get the basic details and get the bank details in second one. And both of them going to save in different domains.

class Customer {

String Name
Integer Age
Date DateOfBirth
String FatherOrHusbandName  
String IdProof
String IdProofNumber
Boolean IsDeleted   

static hasOne = [bankdetail:BankDetails]

static hasMany = [property:Property]

static constraints = {
}}

Bank details

class BankDetails {

String bank_name
String account_number
String account_holder_name
String branch_name
String IFSC_code
String account_type

Customer customer   

static constraints = {
    customer unique:true
}

static mapping = {
    customer insertable: false
    customer updateable: false
}}

These two domain classes are used for the customer. I got the nice tutorial for web flow implementation from http://ridingthetiger.wikia.com/wiki/Creating_the_Example_Grails_WebFlow_Project. But in this tutorial only one domain is used. I want the grails webflow example with two or more domain classes. Please suggest if a have any or give one simple example....

Thanks in advance

Was it helpful?

Solution

Basically, what I do is create two command objects and pass them around through next and previous. One for each step. But in this case the domain objects are simple you can just pass them around in the flow object. e.g

def createCustomerFlow = {
    basicInfo{
        on('next'){Customer cust ->
            flow.customer = cust

            if(!cust.validate()){
                flow.errorbean = cust
                return error()
            }else{
                return success()
            }
        }.to 'bankInfo'
            on("cancel").to 'cancel'
    }
    bankInfo{
        on('finish'){BankDetails bank ->
            flow.bank = bank

            if(!bank.validate()){
                flow.errorbean = bank
                return error()
            }else{
                try{
                    //create customer. Implement this method yourself
                    def cust = createCustomer(flow.customer, flow.bank)

                    flow.customer = cust
                }catch(ValidationException e){
                    log.error("Validation exception", e)
                    flow.errorbean = e
                    return error()
                }
                return success()
            }
        }.to 'summary'
        on("previous"){BankDetails bank ->
            flow.bank = bank
        }.to 'basicInfo'
        on("cancel").to 'cancel'
    }
}      
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top