bobs
bobs

Reputation: 1

How to retain Form Parameters in Grails

I have a similar problem here. I have a page which accepts 3 parameters. i enter the parameters and the control goes to the list action. The list action has the code to query db and get the data on list.gsp page. Now when i hit "download to excel" on the same page, i want the same list action to get triggered and the same query to be run. However, when I click on "export to Excel", control goes to the list action, but the data that i had entered for my query to run is now null. The form elements have not been retained. Please help.

I am using the export plugin

Upvotes: 0

Views: 1739

Answers (1)

Aaron Saunders
Aaron Saunders

Reputation: 33335

Pass the same parameter values back to the controller when the export button is clicked, send them back to the page as "listParams"

[ bookInstanceList: Book.list( params ), listParams: params ]

I might also suggest that you have a different action handle the click on the export button since you really do not want to list the data, you want to export it.

The formats tag supports the following attributes and allows you to pass through HTML attributes:

  • formats (Formats which should be displayed, List of Strings, e.g. ['csv', 'excel', 'ods', 'pdf', 'rtf', 'xml'])
  • params (Additional request
  • parameters, Map, e.g. [sort:params?.sort, order: params?.order])
  • action (Action which should be called, defaults to current action)
  • controller (Controller which should be called, defaults to current controller)

http://www.grails.org/plugin/export

<export:formats params="${listParams}"/>

Upvotes: 1

Related Questions