navigation in JSF when downloading the results to CSV .. html in CSV files
843844Jul 8 2008 — edited Oct 20 2010Hi,
I am new to JSF and am struggling with navigation.
I tried using CommandLink and CommandButton to invoke the action in the backing bean.
I am either getting html code written in the .CSV file or the click on the
link is working in alternate attempts.. Please respond as soon as possible
Below is the code in the backing bean :
public String getHardCopyContactsFilterResultsAsCSV(){
this.setFilterReportPrefId("HARDCOPY");
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ectx.getResponse();
response.setHeader("Content-disposition",
"attachment; filename=Hard Copy Contacts Fliter Results Report.csv");
E contec response.setContentLength(getHeaderForFliterResultsReport().length());
response.setContentType("application/text");
//response.getWriter();
try {
response.getOutputStream().write(getHeaderForFliterResultsReport().getBytes());
if(this.hardcopyResultsDTO!=null){
response.getOutputStream().write(getHardCopyContactsForFilterReport().getBytes());
}
response.getOutputStream().flush();
response.getOutputStream().close();
//context.responseComplete();
} catch (Exception e) {
e.printStackTrace();
}
return "temporaryPage";
}
Note:: I Tried to comment and uncomment the context.reponseComplete() .
Case A:)When The above line is commented i.e responseComplete is called what I am observing is once I click the link to view the Results as .CSV First time I am able to save the results once I try to clik the se cond time the page is getting refreshed rather than opening the dialog as shown for the first attempt.
Every alternate attempt it is working as required i.e opening a dialog.
Case B:
Here the line responseComplete is commented. So when click on link every time a dialog opens
But what I see in te saved .CSV file is the Html code also rendered after the results written in the JSP