output ArrayList to excel in jsf
Hi,
I want to show an arraylist (or a string with data if arraylist is not possible) in excel format within my jsf page, but i don't want to save the data to a file first... is this possible?
I've tried to do the following, but the data is not what i wanted...
public String generateExcelOutput(List list){
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream;
try{
objectOutputStream =new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(list);
}catch (IOException e){
thrownew FacesException(e);
}
byte[] excelData = byteArrayOutputStream.toByteArray();
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
response.setContentType("application/vnd.ms-excel");
response.setContentLength(excelData.length);
try{
ServletOutputStream out;
out = response.getOutputStream();
out.write(excelData);
}catch (IOException e){
thrownew FacesException(e);
}
faces.responseComplete();
returnnull;
}
--> a popup disappears with the question to save or open...that's correct but i also get a notice that the file is corrupt and the data is not shown as it should be...
Can anyone help me, perhaps with an example...
Thanks!

