-
1. Re: save zip file
bleathem Nov 7, 2013 6:53 PM (in response to manuel.moroni)Have you tried using the mediaOutput tag?
http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=mediaOutput&skin=blueSky
-
2. Re: save zip file
manuel.moroni Nov 8, 2013 5:24 AM (in response to bleathem)i'm a complete noob....
i tried but it dues not work
<a4j:mediaOutput element="allegati" cacheable="false" createContent="#{sessionContainer.findSession.allegato.processDownloadAllegato}" uriAttribute="href" mimeType="application/zip">
<h:graphicImage url="../........." title="download"/>
</a4j:mediaOutput>
public void processDownloadAllegato(OutputStream out, Object data) throws ParseException, SQLException
{
logStatistic("------------------------------ START METHOD processDownloadAllegato ------------------------------");
FacesContext fc = FacesContext.getCurrentInstance();
String listLegame="";
List<Allegato> allegati=new ArrayList<Allegato>();
// HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
try
{
for(Allegato all:listMarca){
//listLegame+=all.getIdDocumento()+";";
if(all.getSelected()){
listLegame+=all.getIdDocumento()+";";
}
}
logInfo("lista legami: "+listLegame);
logInfo("size listMarca: "+listMarca.size());
allegati=allegatiDBMng.downloadAllegatiFromDB(listLegame);
listLegame="";
//FileOutputStream fos = new FileOutputStream("/rcg/resources/RCG/zip.zip");
//ZipOutputStream zos=new ZipOutputStream(out);
ZipOutputStream zos= (ZipOutputStream) data;
// ZipOutputStream zos=new ZipOutputStream(response.getOutputStream());
byte[] buffer=new byte[1024];
int len;
int zipSize=0;
for(Allegato a:allegati){
ZipEntry ze=new ZipEntry(a.getNome());
zos.putNextEntry(ze);
while((len=a.getDocumento().read(buffer))>0){
zos.write(buffer,0,len);
zipSize+=len;
}
a.getDocumento().close();
}
zos.closeEntry();
zos.close();
// response.setContentType("application/zip");
// response.setHeader("Pragma", "no-cache");
// response.setHeader("Content-Encoding", "zip");
// response.setHeader("Content-Disposition", "attachment;filename="+System.currentTimeMillis()+".zip");
// response.setHeader("Content-disposition", "attachment;filename=zip.zip");
// response.setHeader("Content-Length", ""+zipSize);
// response.setHeader("Expires", "0");
// response.getOutputStream().flush();
// response.getOutputStream().close();
fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Download eseguito con successo.", ""));
// ret = "OK";
} catch(Exception x)
{
logError("processDownloadAllegato", x);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, x.getMessage(), x.getMessage());
FacesContext.getCurrentInstance().addMessage(null, message);
}
logStatistic("------------------------------ END METHOD processDownloadAllegato ------------------------------");
// return ret;
}
-
3. Re: save zip file
bleathem Nov 8, 2013 9:23 AM (in response to manuel.moroni)Any errors in your browser console? Anything in your server log? Also, what version of RichFaces are you using?
-
4. Re: save zip file
manuel.moroni Nov 8, 2013 9:32 AM (in response to bleathem)no error and no logs at all.
setting properly the response i got it to work but i'm interesting on the use of the component itself.
the richfaces version is 3.3.3 (migrating to 4.3.3 meanwhile)