如何设置 grails 导出插件的 export:formats 元素中的 params 属性值
我已经安装了 grails 导出插件。它有一个元素 export:formats ,它采用 params 值作为属性。我想知道如何将其他元素的值设置到此 params 属性上,以便我的控制器操作可以使用它。
<div id="exportDetail">
<g:select name="reportType" from="${['Daily', 'Weekly Hour', 'Weekly Day']}" ></g:select><br/>
<g:datePicker name="reportStartDate" precision="hour"></g:datePicker><br/>
<g:datePicker name="reportEndDate" precision="hour"></g:datePicker><br/>
<export:formats action="exportRollup" formats="['csv', 'excel', 'ods', 'pdf', 'rtf', 'xml']" params="[**how to pass select, datepicker stuff here to controller**]"/>
</div>
I have installed the grails export plugin. It has an element export:formats which takes a params value as attribute. I want to know how to set values from other elements onto this params attribute so that it is available to my controller action.
<div id="exportDetail">
<g:select name="reportType" from="${['Daily', 'Weekly Hour', 'Weekly Day']}" ></g:select><br/>
<g:datePicker name="reportStartDate" precision="hour"></g:datePicker><br/>
<g:datePicker name="reportEndDate" precision="hour"></g:datePicker><br/>
<export:formats action="exportRollup" formats="['csv', 'excel', 'ods', 'pdf', 'rtf', 'xml']" params="[**how to pass select, datepicker stuff here to controller**]"/>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供给 taglib 的参数只会影响 Grails 呈现的链接。如果您希望链接包含在页面渲染后更改的参数(例如日期选择器选择的值),那么您需要使用 Javascript。这是一个粗略的示例:
理想情况下,您的导出按钮将提交包含日期选择器的表单,并且您不需要使用 Javascript。您必须编写自己的格式标签库才能做到这一点。这将帮助您开始:
namespace = 'export'
,这样它就可以覆盖插件的标签。将formats
标记从ExportTagLib
复制到新标记库。标记更改为提交按钮:
input(type: 'submit', name: 'format', value: format)
input(type: 'image', name: 'format', value: format, src: g.resource(plugin: 'export', dir: 'images/skin', file: format + '.png'))
标记周围添加一个您将无法再在控制器中使用 params.extension ,但从格式中找出文件扩展名并不难。
The params you give to the taglib will only affect the link rendered by Grails. If you want the link to contain params that change after page rendering, such as the values selected by the datepickers, then you need to use Javascript. Here's a rough example:
Ideally, your export buttons would submit a form containing the datepickers, and you would not need to use Javascript. You would have to write your own formats taglib to do that. This'll get you started:
namespace = 'export'
, so it can override the plugin's tags. Copy theformats
tag fromExportTagLib
to your new taglib.<a>
tag to a submit button:input(type: 'submit', name: 'format', value: format)
input(type: 'image', name: 'format', value: format, src: g.resource(plugin: 'export', dir: 'images/skin', file: format + '.png'))
<form>
tag around your<export:formats>
tag in your GSP.You won't be able to use
params.extension
in your controller anymore, but it's not hard to figure out the file extension from the format.