views:

94

answers:

2

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

A: 

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}"/>
Aaron Saunders
Hi Aaron,I am sorry , but could you tell me how do u do that.I mean the below will take me to another action. But how do i pass the parameters, I meamn where do i put the code that you have written
Megs
Thanks Aaron. i am aboe to send parametes now to the controller.
Megs
wver there is an exception that I ma getting, the parameters are empId, empName and empDate. This empDate is Date in my doamin file.
Megs
I convert it to string for my query call like
Megs
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MMM-yyyy")String date = sdfSource.format(empDt);
Megs
Now I get this exception errors.GrailsExceptionResolver - Cannot format given Object as a Date. Any help
Megs
Hi Aaron, Below is my code for calling the action and passing parameters params="[empId:params?.empId, empname: params?.empname, empDt: params.empDt] Now this date is passed as Tue Sep 07 00:00:00 EDT 2010 My code cracks on the line
Megs
Below is the line where it cracks SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MMM-yyyy")String date = sdfSource.format(empDt); ----This line it cracks....Please advice
Megs
Somebody please reply
Megs
your date format in incorrect now, that is why you are getting the exception.
Aaron Saunders
Yes...but how do I correct that?? I mean below is the way I am passing the parameters and in this , date is passed in that format.Below is the way I have written the parameters. <export:formats formats="['excel']" , params="[empId:params?.empId, empName: params?.empName, empDt: params?.empDt]" />
Megs
http://www.grails.org/GSP+Tag+-+formatDate?xhr=true
Aaron Saunders
Thx Aaron. Is there a way I can do the format changes in my controller? When I use the <g:format> tag in my gsp, I am getting errors. Below is the code that i wrote in my gsp. This is the code in my list gsp that displays all the data in table format. The code is <h3> Download to: </h3> <!-- <g:formatDate format="yyyy-MM-dd" empDt:="${empDt:}"/> --> <export:formats formats="['excel']" , params="[empId:params?.empId, empName: params?.empName, empDt: params?.empDt]" />
Megs
use the same format code from before in your controller
Aaron Saunders
You mean use <g:formatDate format="yyyy-MM-dd" date="${date}"/>in my controller list action??
Megs
Could you please let me know what I should write to use the same format code??
Megs
Here in my code <export:formats formats="['excel']" , params="[empId:params?.empId, empName: params?.empName, empDt: params?.empDt]" /> the empDt is passed as a String. Is there a way that I can convert this to a date before Firing the export?
Megs
use <g:formatDate format="yyyy-MM-dd" date="${date}"/> to convert date to appropriate string format in the gsp
Aaron Saunders
This is what I have in my list.gsp now. But I still get a String format .Please advice. <export:formats formats="['excel']" , params="[empId:params?.empId, empName: params?.empName, empDt: params?.empDt]" /> <g:formatDate format="yyyy-MM-dd" date="${empDt}"/>Am I doing something wrong here?
Megs
Could someone tell me how to use <g:formatDate format tag in my code...plsss
Megs
any help???????
Megs
A: 

Hi Aaron,

I am sorry , but could you tell me how do u do that.

I mean the below will take me to another action. But how do i pass the parameters, I meamn where do i put the code that you have written

Download to:

Megs
this should be a comment not an answer...
Aaron Saunders
sorry Aaron..using this site for the first time..got confused
Megs