Good evening I need your help
Please I have an interface with a button that allows the user to generate the list of customers available in the database in pdf format. I worked with jasper ireport. The problem is that by clicking on the button I have no result and no exception. The page refreshes only .Here is the code:
public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}
public Connection getDataSourceConnection(String dataSourceName) throws Exception {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(dataSourceName);
return ds.getConnection();
}
private Connection getConnection() throws Exception {
return getDataSourceConnection("jdbc/SwiftDS"); // use datasourse in your application
}
public ServletContext getContext() {
return (ServletContext) getFacesContext().getExternalContext().getContext();
}
public HttpServletResponse getResponse() {
return (HttpServletResponse) getFacesContext().getExternalContext().getResponse();
}
public static FacesContext getFacesContext() {
return FacesContext.getCurrentInstance();
}
public void runReport(String repPath, java.util.Map param) throws Exception {
Connection conn = null;
try {
HttpServletResponse response = getResponse();
System.out.println("Response : " + response);
ServletOutputStream out = response.getOutputStream();
response.setHeader("Cache-Control", "max-age=0");
response.setContentType("application/octet-stream");
ServletContext context = getContext();
InputStream fs = context.getResourceAsStream("/reports/" + repPath);
System.out.println("Response : " + repPath);
System.out.println("Response : " + fs);
JasperReport template = (JasperReport) JRLoader.loadObject(fs);
System.out.println("Template : " + template);
template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
conn = getConnection();
JasperPrint print = JasperFillManager.fillReport(template, param, conn);
System.out.println("PDF" + print);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(print, baos);
System.out.println("PDF" + baos);
out.write(baos.toByteArray());
System.out.println("Printed");
out.flush();
out.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (Exception jex) {
jex.printStackTrace();
} finally {
close(conn);
}
}
public void close(Connection con) {
if (con != null) {
try {
con.close();
} catch (Exception e) {
}
}
}
public void runReportAction(ActionEvent actionEvent) {
try {
System.out.println("test");
runReport("reportCustody.jasper", null);
} catch (Exception e) {
}
}