//In PFR
if (pageContext.getParameter("GeneratePacklist") != null) //CSV file export after click event
{
String[] ss = { "Selectflag" };
downloadCsvFile(pageContext, "xx_tempvo1", "TPCEXPORT", "MAX", ss);
}
Put submit button on the UI and raise an export event on the same.
//Write below code after PFR curly braces close
public void downloadCsvFile(OAPageContext pageContext, String view_inst_name, String file_name_without_ext, String max_size, String[] hidden_attrib_list) {
OAViewObject v = (OAViewObject)pageContext.getRootApplicationModule().findViewObject(view_inst_name);
if (v == null)
{
throw new OAException("Could not find View object instance " + view_inst_name + " in root AM.");
}
if (v.getFetchedRowCount() == 0)
{
throw new OAException("There is no data to export.");
}
String file_name = "Export";
if ((file_name_without_ext != null) && (!"".equals(file_name_without_ext)))
{
file_name = file_name_without_ext;
}
HttpServletResponse response = (HttpServletResponse)pageContext.getRenderingContext().getServletResponse();
response.setContentType("application/text");
response.setHeader("Content-Disposition", "attachment; filename=" + file_name + ".csv");
PrintWriter pw = null;
try
{
pw = response.getWriter();
int j = 0;
int k = 0;
boolean bb = true;
if ((max_size == null) || ("".equals(max_size)))
{
k = Integer.parseInt(pageContext.getProfile("VO_MAX_FETCH_SIZE"));
bb = false;
}
else if ("MAX".equals(max_size))
{
bb = true;
}
else
{
k = Integer.parseInt(max_size);
bb = false;
}
AttributeDef[] a = v.getAttributeDefs();
StringBuffer cc = new StringBuffer();
ArrayList exist_list = new ArrayList();
for (int l = 0; l < a.length; l++)
{
boolean zx = true;
if (hidden_attrib_list != null)
{
for (int z = 0; z < hidden_attrib_list.length; z++)
{
if (!a[l].getName().equals(hidden_attrib_list[z]))
continue;
zx = false;
exist_list.add(String.valueOf(a[l].getIndex()));
}
}
if (!zx)
continue;
cc.append("\"" + a[l].getName() + "\"");
cc.append(",");
}
String header_row = cc.toString() + "\n";
pw.write(header_row);
for (OAViewRowImpl row = (OAViewRowImpl)v.first(); row != null; row = (OAViewRowImpl)v.next()) {
if (row.getAttribute("Selectflag") == null)
continue;
if (!row.getAttribute("Selectflag").toString().equals("Y"))
continue;
StringBuffer strbuff = new StringBuffer();
for (int i = 0; i < a.length - 1; i++) {
strbuff.append(row.getAttribute(i));
strbuff.append(",");
}
strbuff.append("\n");
pw.write(strbuff.toString());
}
}
catch (Exception e)
{
e.printStackTrace();
throw new OAException("Unexpected Exception occured.Exception Details :" + e.toString());
}
finally
{
pw.flush();
pw.close();
}
}
if (pageContext.getParameter("GeneratePacklist") != null) //CSV file export after click event
{
String[] ss = { "Selectflag" };
downloadCsvFile(pageContext, "xx_tempvo1", "TPCEXPORT", "MAX", ss);
}
Put submit button on the UI and raise an export event on the same.
//Write below code after PFR curly braces close
public void downloadCsvFile(OAPageContext pageContext, String view_inst_name, String file_name_without_ext, String max_size, String[] hidden_attrib_list) {
OAViewObject v = (OAViewObject)pageContext.getRootApplicationModule().findViewObject(view_inst_name);
if (v == null)
{
throw new OAException("Could not find View object instance " + view_inst_name + " in root AM.");
}
if (v.getFetchedRowCount() == 0)
{
throw new OAException("There is no data to export.");
}
String file_name = "Export";
if ((file_name_without_ext != null) && (!"".equals(file_name_without_ext)))
{
file_name = file_name_without_ext;
}
HttpServletResponse response = (HttpServletResponse)pageContext.getRenderingContext().getServletResponse();
response.setContentType("application/text");
response.setHeader("Content-Disposition", "attachment; filename=" + file_name + ".csv");
PrintWriter pw = null;
try
{
pw = response.getWriter();
int j = 0;
int k = 0;
boolean bb = true;
if ((max_size == null) || ("".equals(max_size)))
{
k = Integer.parseInt(pageContext.getProfile("VO_MAX_FETCH_SIZE"));
bb = false;
}
else if ("MAX".equals(max_size))
{
bb = true;
}
else
{
k = Integer.parseInt(max_size);
bb = false;
}
AttributeDef[] a = v.getAttributeDefs();
StringBuffer cc = new StringBuffer();
ArrayList exist_list = new ArrayList();
for (int l = 0; l < a.length; l++)
{
boolean zx = true;
if (hidden_attrib_list != null)
{
for (int z = 0; z < hidden_attrib_list.length; z++)
{
if (!a[l].getName().equals(hidden_attrib_list[z]))
continue;
zx = false;
exist_list.add(String.valueOf(a[l].getIndex()));
}
}
if (!zx)
continue;
cc.append("\"" + a[l].getName() + "\"");
cc.append(",");
}
String header_row = cc.toString() + "\n";
pw.write(header_row);
for (OAViewRowImpl row = (OAViewRowImpl)v.first(); row != null; row = (OAViewRowImpl)v.next()) {
if (row.getAttribute("Selectflag") == null)
continue;
if (!row.getAttribute("Selectflag").toString().equals("Y"))
continue;
StringBuffer strbuff = new StringBuffer();
for (int i = 0; i < a.length - 1; i++) {
strbuff.append(row.getAttribute(i));
strbuff.append(",");
}
strbuff.append("\n");
pw.write(strbuff.toString());
}
}
catch (Exception e)
{
e.printStackTrace();
throw new OAException("Unexpected Exception occured.Exception Details :" + e.toString());
}
finally
{
pw.flush();
pw.close();
}
}
No comments:
Post a Comment