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>
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:
$('.menuButton a').click(function() {
var target = this.href + '&reportStartDate=' + $('#reportStartDate').val();
window.location.href = target;
return false;
});
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 the formats
tag from ExportTagLib
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.