You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/02 19:04:37 UTC
svn commit: r960057 -
/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java
Author: sabob
Date: Fri Jul 2 17:04:37 2010
New Revision: 960057
URL: http://svn.apache.org/viewvc?rev=960057&view=rev
Log:
simplified export demo using pageAction
Modified:
click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java
Modified: click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java?rev=960057&r1=960056&r2=960057&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelExportPage.java Fri Jul 2 17:04:37 2010
@@ -20,14 +20,12 @@ package org.apache.click.examples.page.g
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
-import org.apache.click.ActionListener;
-import org.apache.click.Control;
+import org.apache.click.Partial;
import org.apache.click.control.ActionLink;
import org.apache.click.examples.domain.Customer;
import org.apache.click.examples.page.BorderPage;
@@ -61,57 +59,40 @@ public class ExcelExportPage extends Bor
super.onInit();
ActionLink link = new ActionLink("export");
- link.setActionListener(new ActionListener() {
- private static final long serialVersionUID = 1L;
- public boolean onAction(Control source) {
- export();
- return false;
- }
- });
+ // A "pageAction" is set as a parameter on the link. The "pageAction"
+ // value is set to the Page method: "renderSpreadsheet"
+ link.setParameter(PAGE_ACTION, "renderSpreadsheet");
addControl(link);
}
/**
- * Export the spreadsheet.
+ * This is a "pageAction" method and will render the Excel spreadsheet.
+ *
+ * Note the signature of the pageAction: a public, no-argument method
+ * returning a Partial instance.
*/
- public void export() {
-
+ public Partial renderSpreadsheet() {
HttpServletResponse response = getContext().getResponse();
HSSFWorkbook wb = createWorkbook();
// Set response headers
- String mimeType = ClickUtils.getMimeType(".xls");
response.setHeader("Content-Disposition", "attachment; filename=\"report.xls\"");
- response.setContentType(mimeType);
response.setHeader("Pragma", "no-cache");
-
- OutputStream outputStream = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
wb.write(baos);
- byte[] bytes = baos.toByteArray();
-
- response.setContentLength(bytes.length);
+ String contentTyype = ClickUtils.getMimeType(".xls");
+ Partial partial = new Partial(baos.toByteArray(), contentTyype);
- outputStream = response.getOutputStream();
-
- // Write out Excel Workbook to response stream
- outputStream.write(bytes);
- outputStream.flush();
-
- // Specify no further rendering required
- setPath(null);
+ return partial;
} catch (IOException ioe) {
throw new RuntimeException(ioe);
-
- } finally {
- ClickUtils.close(outputStream);
}
}