<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Webdings;
panose-1:5 3 1 2 1 5 9 6 7 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=NO-BOK link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Hi Àlex,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Silly question perhaps, but since it’s not completely apparent from the code you provided: Are you missing something like <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>resp.getWriter().write(buffer.toString()); <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Just returning won’t do much (and that fits with what you’re experiencing).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Cheers,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Paul<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> opencms-dev-bounces@opencms.org [mailto:opencms-dev-bounces@opencms.org] <b>On Behalf Of </b>Àlex Rodríguez Bacardit<br><b>Sent:</b> 14. oktober 2013 17:56<br><b>To:</b> opencms-dev@opencms.org<br><b>Subject:</b> [opencms-dev] Download a file from administration point<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>Hi,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>I’m trying to create a dialog to download a file for an administration point (à la <span style='background:silver;mso-highlight:silver'>CmsUsersCsvDownloadDialog</span>) to download an html file with a certain content. The class extends CmsWidgetDialog<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>I’ve generated a method downloadFile() that redirects a StringBuffer to the response, that makes like this:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>...<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:black'> </span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>StringBuffer buffer = </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>new</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> StringBuffer();</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> HttpServletResponse resp = CmsFlexController.<i>getController</i>(getJsp().getRequest()).getTopResponse();</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> resp.setContentType(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>"text/html"</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> buffer.append(exportFileContent);</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> resp.setHeader(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>"Content-Disposition"</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>, </span><b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>new</span></b><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> StringBuffer(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>"attachment; filename=\""</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>).append(filename).append(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>"\""</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>).toString());</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> resp.setContentLength(buffer.length());</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'> </span><i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#0000C0'>LOG</span></i><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:black'>.info(</span><span lang=EN-US style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>"End actionCommit() method. </span><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:#2A00FF'>Buffer content: "</span><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:black'> + buffer.toString());</span><span lang=ES style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:black'> </span><span lang=ES style='font-size:10.0pt;font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:black'> </span><b><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:#7F0055'>return</span></b><span lang=ES style='font-size:10.0pt;font-family:Consolas;color:black'> buffer.toString();</span><span lang=EN-US><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>The buffer.toString() method returns, of course, the correct value. That is, the content of the StringBuffer. However, I’m getting a blank .html file with no content inside. What could have possibly gone wrong?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Thanks in advance,<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:5.95pt'><span lang=ES style='font-size:10.0pt;color:#1F497D'><a href="http://www.linkedin.com/in/alexrodba"><b><span lang=EN-US style='color:#1F497D'>Àlex Rodríguez Bacard</span></b><b><span style='color:#1F497D'>it</span></b></a></span><span lang=ES style='font-size:10.0pt;color:navy'><br></span><span lang=ES style='font-size:10.0pt;color:#1F497D'>Consultor</span><span lang=ES style='font-size:10.0pt;color:navy'> e-Business<br><a href="mailto:alex.rodriguez@vass.es">alex.rodriguez@vass.es</a></span><span lang=ES style='font-size:10.0pt;color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:5.95pt'><b><span lang=ES style='font-size:10.0pt;color:gray'>VASS Consultoría de Sistemas</span></b><b><span lang=ES style='font-size:10.0pt;color:#1F497D'><br></span></b><span lang=ES style='font-size:10.0pt;color:gray'>Tel: +34 93 182 0963<br>Fax: +34 933 184 291<br>Avinguda Diagonal 210, 4a planta<br>08018 Barcelona<br><a href="http://www.vass.es/"><span style='color:black'>www.vass.es</span></a><o:p></o:p></span></p><p class=MsoNormal style='mso-line-height-alt:6.0pt'><span lang=ES style='font-size:7.5pt;font-family:"Verdana","sans-serif";color:#999999'>Este correo electrónico así como los documentos adjuntos contienen información confidencial y reservada. Si ha recibido este mensaje por error siga las instrucciones contenidas en nuestro </span><span lang=ES style='color:#1F497D'><a href="http://vass.es/es/aviso-legal"><span style='font-size:7.5pt;font-family:"Verdana","sans-serif"'>Aviso Legal</span></a></span><span lang=ES style='font-size:7.5pt;font-family:"Verdana","sans-serif";color:#999999'>. Si no deseara recibir más comunicaciones por correo electrónico comuníquelo en la siguiente dirección: </span><span lang=ES style='color:#1F497D'><a href="mailto:general@vass.es"><span style='font-size:7.5pt;font-family:"Verdana","sans-serif"'>general@vass.es</span></a></span><span lang=ES style='font-size:7.5pt;font-family:"Verdana","sans-serif";color:#999999'> <o:p></o:p></span></p><p class=MsoNormal><span lang=ES-TRAD style='font-size:9.0pt;font-family:Webdings;color:green'>P</span><span lang=ES-TRAD style='font-size:7.5pt;font-family:"Tahoma","sans-serif";color:blue'> </span><span lang=ES-TRAD style='font-size:7.0pt;font-family:"Tahoma","sans-serif";color:olive'>Antes de imprimir este mensaje, asegúrese de que es necesario. El medio ambiente está en nuestra mano.</span><span lang=ES-TRAD style='font-size:7.5pt;font-family:"Tahoma","sans-serif";color:olive'><o:p></o:p></span></p><p class=MsoNormal><span lang=ES><o:p> </o:p></span></p></div></body></html>