LifeCycle Question
Hi all!
I have a method that allows a file to be downloaded to the user's hard-drive.
My problem is that the life cycle seems to stop when they save the file
i.e. the page they are on is not refreshed! Can anyone help me?
I need the page to be redisplayed because they are dealing with records in a table, those records are removed as they are dealt with, but the screen doesn't refresh so the records stay on the screen even though they are dealt with.
This has something to do with the one request one response thing in HTML? Any workarounds available? Thanks!
Here is the method code:
publicstaticfinalvoid returnFile(ByteArrayOutputStream baos, String contentType, String fileName)throws Exception
{
try
{
FacesContext ctx = FacesContext.getCurrentInstance();
ServletOutputStream out =null;
if (!ctx.getResponseComplete()){
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
response.setContentType(contentType);
StringBuffer sb =new StringBuffer(60);
sb.append("attachment;filename=\"");
sb.append(fileName);
sb.append("\"");
response.setHeader("Content-Disposition", sb.toString());
out = response.getOutputStream();
out.write(baos.toByteArray());
out.flush();
out.close();
ctx.responseComplete();
}
}
catch(Exception e)
{
thrownew Exception("could not return file", e);
}
}

