Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

navigation in JSF when downloading the results to CSV .. html in CSV files

843844Jul 8 2008 — edited Oct 20 2010
Hi,
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2010
Added on Jul 8 2008
5 comments
376 views