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!

How to pass datatable values to Excel sheet from jsf page

843844Jul 8 2008 — edited Jul 9 2008
Hi,
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;

}


}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2008
Added on Jul 8 2008
6 comments
389 views