1. Take One Button whose style is "exportButton"
Then write following code in controller change the vo according to requirement.
if(pageContext.getParameter("ExportActive")!=null)
{
String emp_no = null;
String emp_name = null;
String site_name = null;
System.out.println("Export Active Button Pressed");
//OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject trCallVO = (OAViewObject)am.findViewObject("EmpVO");
try
{
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
response.setContentType("application/text");
response.setHeader("Content-Disposition","attachment; filename=" + "Full Population Report" + ".csv");
PrintWriter pw = null;
pw = response.getWriter();
//Writing the headers
pw.write("Employee Number");
pw.write(",");
pw.write("Employee Name");
pw.write(",");
pw.write("Job");
pw.write("\n");
// getting table data
if(trCallVO!=null)
{
for(EmpVORowImpl row = (EmpVORowImpl)trCallVO.first();row!=null;row =(EmpVORowImpl)trCallVO.next())
{
if(row.getEmpno()!=null)
{
// pw.write(row.getEmployeeFullName().replaceAll((",",".")));
emp_no = row.getEmpno().toString();
pw.write(emp_no);
}
else
{
pw.write(" ");
}
pw.write(",");
if(row.getEname()!=null)
{
pw.write(row.getEname());
}
else
{
pw.write(" ");
}
pw.write(",");
if(row.getJob()!=null)
{
pw.write(row.getJob());
}
else
{
pw.write(" ");
}
pw.write("\n");
}
pw.write(" ");
pw.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Then write following code in controller change the vo according to requirement.
if(pageContext.getParameter("ExportActive")!=null)
{
String emp_no = null;
String emp_name = null;
String site_name = null;
System.out.println("Export Active Button Pressed");
//OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject trCallVO = (OAViewObject)am.findViewObject("EmpVO");
try
{
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
response.setContentType("application/text");
response.setHeader("Content-Disposition","attachment; filename=" + "Full Population Report" + ".csv");
PrintWriter pw = null;
pw = response.getWriter();
//Writing the headers
pw.write("Employee Number");
pw.write(",");
pw.write("Employee Name");
pw.write(",");
pw.write("Job");
pw.write("\n");
// getting table data
if(trCallVO!=null)
{
for(EmpVORowImpl row = (EmpVORowImpl)trCallVO.first();row!=null;row =(EmpVORowImpl)trCallVO.next())
{
if(row.getEmpno()!=null)
{
// pw.write(row.getEmployeeFullName().replaceAll((",",".")));
emp_no = row.getEmpno().toString();
pw.write(emp_no);
}
else
{
pw.write(" ");
}
pw.write(",");
if(row.getEname()!=null)
{
pw.write(row.getEname());
}
else
{
pw.write(" ");
}
pw.write(",");
if(row.getJob()!=null)
{
pw.write(row.getJob());
}
else
{
pw.write(" ");
}
pw.write("\n");
}
pw.write(" ");
pw.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
No comments:
Post a Comment