Search code examples
grails

How can I redirect two actions instead of one action


here is my controller:

def save = {
    def productNameInstance = new ProductName(params)
    if (pharmacyMasterUpdateCompositeService.addProductName(productNameInstance)) {
        flash.message = "${message(code: 'default.created.message', args: [message(code: 'productName.label', default: 'ProductName'), productNameInstance.id])}"
        redirect(action: "show", id: productNameInstance.id)
    }
    else {
        render(view: "create", model: [productNameInstance: productNameInstance])
    }
}

where addProductName(productNameInstance) is calling service that is defined in another class. Here if you see redirecting is happening only at action :"show" if page is created. My problem is how can i redirect two action like "show" and "print" at the same time where my "print" action downloads a pdf file ?


Solution

  • You can use the chain method.

    def save = {
    def productNameInstance = new ProductName(params)
    if (pharmacyMasterUpdateCompositeService.addProductName(productNameInstance)) {
       //...        
      chain(action: "print", params: [id: roductNameInstance.id])
    }
    else {
        render(view: "create", model: [productNameInstance: productNameInstance])
    }
    
    def print = {
    //...
    chain(action: "show", params: params)
    }
    
    def show  = {  }
    
    
    }