2014-01-14 91 views
1

我想在g:uploadForm提交後重定向頁面。grails在uploadForm後重定向

我的g:uploadForm操作是保存。

另存爲:

@Transactional 
def save(DesignCategory designCategoryInstance) { 
    if (designCategoryInstance == null) { 
     notFound() 
     return 
    } 

    if (designCategoryInstance.hasErrors()) { 
     respond designCategoryInstance.errors, view: 'create' 
     return 
    } 

    def disotypeFile = request.getFile('disotype1') 
    if(!disotypeFile.empty){ 
     print('here') 
     def fname = disotypeFile.getOriginalFilename() 
     def fileAtt = new FileAttachment() 
     fileAtt.originalFilename = fname 
     fileAtt.newFilename = "disotype-" 
     fileAtt.fileURI = '/Users/work/Desktop/files/' + fileAtt.newFilename 
     disotypeFile.transferTo(new File(fileAtt.fileURI)) 
     response.sendError(200, 'Done') 
     fileAtt.save(flush: true) 
     designInstance.disotype = fileAtt; 
    } 

     designCategoryInstance.save flush: true, failOnError:true 

    flash.message = message(code: 'default.created.message', args: [message(code: 'designCategoryInstance.label', default: 'DesignCategory'), designCategoryInstance.id]) 
    redirect designCategoryInstance 

} 

這提供了以下錯誤:

Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.. Stacktrace follows: 
Message: Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response. 

這並不工作,如果我拿出

def disotypeFile = request.getFile('disotype1') 

但很明顯,我不能讓文件。

有什麼想法?

回答

2

嘗試刪除行:

response.sendError(200, 'Done')