Attached is a patch file for the export.filename support. With this, you can add the following line to src/webapp/example-export.jsp, it sets the filename for the download:

<display:setProperty name="export.filename" value="exportfile" />

Hopefully the changes make sense.

--
Serge Knystautas
President
Lokitech >>> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. [EMAIL PROTECTED]

John York wrote:
Hi Serge, if you'd like to write this feature, we can definitely incorporate it into our codebase. The best way to do this is provide us a patch for the files that you are changing and then we can take a look at it and merge it in. I believe sourceforge has more information about patching if you need it.

John


On Tue, 13 Jan 2004, Serge Knystautas wrote:



I've been following displaytags from a distant, and finally looking at incorporating in some of our code.

One feature that seems to be started that I would definitely need is to set the download filename during an export. This would require setting the content disposition header in the response with the filename, not too hard to do.

I say this was started because there is an undocumented export.filename property PROPERTY_STRING_EXPORT_FILENAME (export.filename) and TableProperties.getExportFileName(). However, this is never called during TableTag.writeExport(mimeType, exportString).

Is there any interest in such a patch to complete this feature? It doesn't look like very much work.. just patches to TableTag and ResponseOverrideFilter. Anything I'm missing, and anything special about how you like contributions?






Index: src/java/org/displaytag/export/BaseExportView.java
===================================================================
RCS file: 
/cvsroot/displaytag/displaytag2/src/java/org/displaytag/export/BaseExportView.java,v
retrieving revision 1.8
diff -w -b -r1.8 BaseExportView.java
116a117,121
>      * Extension for this file.
>      */
>     public abstract String getExtension();
> 
>     /**
Index: src/java/org/displaytag/export/CsvView.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/export/CsvView.java,v
retrieving revision 1.6
diff -w -b -r1.6 CsvView.java
94a95,102
>      * @see org.displaytag.export.BaseExportView#getExtension()
>      */
>     public String getExtension()
>     {
>         return "csv";
>     }
> 
>     /**
Index: src/java/org/displaytag/export/ExcelView.java
===================================================================
RCS file: 
/cvsroot/displaytag/displaytag2/src/java/org/displaytag/export/ExcelView.java,v
retrieving revision 1.5
diff -w -b -r1.5 ExcelView.java
31a32,39
>      * @see org.displaytag.export.BaseExportView#getExtension()
>      */
>     public String getExtension()
>     {
>         return "xls";
>     }
> 
>     /**
Index: src/java/org/displaytag/export/XmlView.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/export/XmlView.java,v
retrieving revision 1.5
diff -w -b -r1.5 XmlView.java
94a95,102
>      * @see org.displaytag.export.BaseExportView#getExtension()
>      */
>     public String getExtension()
>     {
>         return "xml";
>     }
> 
>     /**
Index: src/java/org/displaytag/filter/ResponseOverrideFilter.java
===================================================================
RCS file: 
/cvsroot/displaytag/displaytag2/src/java/org/displaytag/filter/ResponseOverrideFilter.java,v
retrieving revision 1.5
diff -w -b -r1.5 ResponseOverrideFilter.java
67a68,73
>      * If the filename is specified, there will be a supplied filename. Request 
> variable.
>      */
>     public static final String CONTENT_OVERRIDE_FILENAME =
>         ResponseOverrideFilter.class.getName() + "CONTENT_OVERRIDE_FILENAME";
> 
>     /**
93a100
>         request.setAttribute(CONTENT_OVERRIDE_FILENAME, new StringBuffer(80));
98a106
>         String filename = "";
103a112
>             filename = "" + request.getAttribute(CONTENT_OVERRIDE_FILENAME);
104a114,117
>             if (filename.length() > 0)
>             {
>                 log.debug("Filename specified as " + filename);
>             }
113a127,131
>         if (filename.length() > 0)
>         {
>             HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
>             httpResponse.setHeader("Content-Disposition", "filename=\"" + filename + 
> "\"");
>         }
Index: src/java/org/displaytag/tags/TableTag.java
===================================================================
RCS file: /cvsroot/displaytag/displaytag2/src/java/org/displaytag/tags/TableTag.java,v
retrieving revision 1.37
diff -w -b -r1.37 TableTag.java
12c12
< import javax.servlet.ServletResponse;
---
> import javax.servlet.http.HttpServletResponse;
989a990,993
>         String filename = properties.getExportFileName();
>         if (filename != null) {
>             filename += "." + exportView.getExtension();
>         }
991c995
<         return writeExport(mimeType, exportString);
---
>         return writeExport(mimeType, exportString, filename);
998a1003
>      * @param filename String
1002c1007
<     protected int writeExport(String mimeType, String exportString) throws 
JspException
---
>     protected int writeExport(String mimeType, String exportString, String filename) 
> throws JspException
1004c1009
<         ServletResponse response = this.pageContext.getResponse();
---
>         HttpServletResponse response = (HttpServletResponse) 
> this.pageContext.getResponse();
1017a1023,1029
>             if (filename != null)
>             {
>                 StringBuffer filenameOverride =
>                     (StringBuffer) request.getAttribute(
>                         
> "org.displaytag.filter.ResponseOverrideFilter.CONTENT_OVERRIDE_FILENAME");
>                 filenameOverride.append(filename);
>             }
1030a1043,1046
>             if (filename != null)
>             {
>                 response.setHeader("Content-Disposition", "filename=\"" + filename + 
> "\"");
>             }

Reply via email to