2013-03-25 40 views
0

我想在我的腳手架控制器中使用withFormat並添加腳手架視圖'list.csv.gsp'。但是,如果不生成我的list.csv.gsp視圖,grails不會使用腳手架list.csv.gsp視圖。腳手架withFormat視圖不起作用

生成de list.csv.gsp視圖後,它工作正常。但我不會創造所有這些觀點,因爲它們都是一樣的。

withFormat { 
     html { 
      [${propertyName}List: ${propertyName}List, ${propertyName}Total: ${propertyName}List.getTotalCount(), params: cleanParams(params)] 
     } 
     csv { 
      response.setContentType('text/csv') 
      response.setHeader('Content-Disposition', "attachment; filename=\${message(code: '${domainClass.propertyName}.label')}.csv") 
      [${propertyName}List: ${propertyName}List] 
     } 
    } 

回答

0

我不知道如果你仍然有這個問題,但與格式Grails的文檔有這樣的話::

我的腳手架控制器列表動作與下面的代碼結束

Grails會忽略HTTP Accept頭,除非您向Config.groovy文件添加grails.mime.use.accept.header = true設置。換句話說,withFormat()將完全不受沒有該設置的Accept頭的影響。

請參閱grails文檔中的withFormat

0

在您的視圖中,您可能需要將其寫入通用目錄並放入通用目錄並引用您的控制器模板以使用它。也許使它成爲_template並渲染它。 希望這有助於。