
here is my code :
public String download(){
if(log.isDebugEnabled()){
log.info("Entered for downloading: ");
}
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
try{
List<TableController> list = fetchTechniciansList();
Iterator<TableController> iter = list.iterator();
ServletOutputStream out = null;
response.reset();`print("code sample");`
response.setContentType("application/csv");
response.setHeader("Cache-Control", "private");
response.setHeader("Pragma", "public");
response.addHeader("Accept-Ranges", "none");
response.setHeader("Content-disposition","inline; filename=\""
+ "technician_list.csv" + "\"");
out=response.getOutputStream();
out.write("First Name".getBytes());
out.write(',');
out.write("Last Name".getBytes());
out.write(',');
out.write("User ID".getBytes());
out.write('\n');
Integer i=0;
while(iter.hasNext()) {
out.write(list.get(i).getFirst_name().getBytes());
out.write(',');
out.write(list.get(i).getBean_last_name().getBytes());
out.write(',');
out.write(list.get(i).getUser_id().toString().getBytes());
out.write('\n');
i++;
iter.next();
}
out.flush();
out.close();
facesContext.responseComplete();
}
catch (Exception e) {
// TODO: handle exception
log.error("downloading error");
log.info("Exited");
}
return null;
}
I have command link in html :
<h:commandLink value="Download Technician List" action="#{tableControllerBean.download}" style="float:right" target="_blank"></h:commandLink>
which calls this download() method . the problem is that list open directly in excel file but not in IE . I am using IE 8 with windows 7.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.