How to pass datatable values to Excel sheet from jsf page
843844Jul 8 2008 — edited Jul 9 2008Hi,
I have a jsf page displaying name and age.
I want these values to display in the excel sheet
the excel sheet is opening when i click the commandlink button but the values are not displyed.
I dont know how to send data from jsf page to excel
please help
Hereby i have attached my java program
package com.cts;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public class ExporttoExcel
{
private String name;
private int age;
private String htmlBuffer;
public void exportHtmlTableToExcel() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
response.setHeader("Content-disposition", "attachment; filename=test.csv" );
String str = "Name\tAge";//**I dont know wat i have to write here**
byte [] csvData = str.getBytes();
response.setContentLength(csvData.length);
response.setContentType("application/msexcel");
response.getOutputStream().write(csvData);
response.getOutputStream().write(csvData);
response.getOutputStream().flush();
response.getOutputStream().close();
context.responseComplete();
}
public void setName(String name){
this.name=name;
}
public void setAge(){
this.age=age;
}
public String getName(){
return "Mangals";
}
public int getAge(){
return 22;
}
public ArrayList getData() {
ExporttoExcel excel=new ExporttoExcel();
ArrayList ret=new ArrayList();
HashMap map=new HashMap(7);
map.put("name", excel.getName());
map.put("age", excel.getAge());
ret.add(map);
return ret;
}
}