Results 1 to 1 of 1
- 06-10-2011, 02:45 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
Subreport doesn't show in the PDF
I would like to show a subreport in the mainreport, but it doesn't show.
in the method showPdfList() builds the pdf
what's wrong?
thanks for help!!!
/**
* Hier wird das PDF mit den Partnern erstellt.
* @return "success"
* @throws Exception
*/
public String showPdfList() throws Exception {
LogBuilder.getLog(PartnerListBean.class).debug("cr eate partner and contract list pdf...");
final FacesContext facesContext = FacesContext.getCurrentInstance();
// Now we create some variables we will use for writing
// the file to the response
// Name des jrxml
final String mainFileName = "partnerList";
final String subFileName = "contractList_subreport";
String fileExt = ".jrxml";
final String base = JasperReportHelper.getJasperConfDirRealPath();
OutputStream outputStream = null;
JasperReport jasperMainReport = null;
JasperReport jasperSubReport = null;
if (base != null) {
try {
final Map<String, JasperReport> params = new HashMap<String, JasperReport>();
// compile main report
// this ist also done in mavens pre-compilation, see: jasperreports-maven-plugin
final JasperDesign jasperDesign = JRXmlLoader.load(base + mainFileName + fileExt);
final JasperDesign subJasperDesign = JRXmlLoader.load(base + subFileName + fileExt);
jasperSubReport = JasperCompileManager.compileReport(subJasperDesign );
jasperMainReport = JasperCompileManager.compileReport(jasperDesign);
params.put("subreport", jasperSubReport);
// eine Collection mit der aktuellen Liste
final JRBeanCollectionDataSource mainCollection =
new JRBeanCollectionDataSource(this.getList());
//eine Collection mit der aktuellen Liste
// final JRBeanCollectionDataSource subCollection =
// new JRBeanCollectionDataSource(this.getList());
final JasperPrint mainJasperPrint = JasperFillManager.fillReport(jasperMainReport, params,
mainCollection);
// final JasperPrint subJasperPrint = JasperFillManager.fillReport(jasperSubReport, params,
// subCollection);
LogBuilder.getLog(PartnerListBean.class).debug("An zahl Partner der Liste: "
+ list.size());
fileExt = ".pdf";
// check if response not null
HttpServletResponse response = null;
if (facesContext != null & facesContext.getExternalContext() != null && facesContext.getExternalContext().getResponse() != null) {
// Then we have to get the Response where to write our file
response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
}
if (response != null) {
// Then we have to get the Response where to write our file
response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
// Now set the content type for our response, be sure to use the
// best suitable content type depending on your file
// the content type presented here is ok for, lets say, text
// files and others (like CSVs, PDFs)
response.setContentType("application/pdf");
// This is another important attribute for the header of the response
// Here fileName, is a String with the name that you will suggest as
//a name to save as
// I use the same name as it is stored in the file system of the server.
response.setHeader("Content-Disposition",
"attachment;filename=\"" + mainFileName + fileExt + "\"");
outputStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(mainJa sperPrint,
outputStream);
} else {
LogBuilder.getLog(PartnerListBean.class).warn(
"we have no response object, writing to pdf file not to response");
JasperExportManager.exportReportToPdfFile(mainJasp erPrint, base + mainFileName + fileExt);
}
} catch (JRException ex) {
LogBuilder.getLog(PartnerListBean.class).error(ex, ex);
return "";
} catch (IOException ex) {
LogBuilder.getLog(ContractListBean.class).error(ex , ex);
return "";
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException ioe) {
LogBuilder.getLog(PartnerListBean.class).warn(ioe, ioe);
}
}
}
} else {
// Warn logging
LogBuilder.getLog(PartnerListBean.class).warn(
"Base of Jasper-Reporter was null, no PDF created");
return "success";
}
// we are finished
if (facesContext != null) {
facesContext.responseComplete();
}
LogBuilder.getLog(PartnerListBean.class).debug("cr eate contract list pdf -> done");
return "success";
}
Similar Threads
-
FrameView doesn't show new JPanel until I resize
By metazone in forum SWT / JFaceReplies: 3Last Post: 01-05-2012, 03:52 PM -
JList doesn't show the elements
By mrbeast87 in forum AWT / SwingReplies: 2Last Post: 04-20-2011, 06:21 PM -
jTextPane doesn't show HTML
By indra-uolles in forum AWT / SwingReplies: 5Last Post: 08-31-2010, 02:29 PM -
Animation doesn't show when used as action?
By ryuzog in forum New To JavaReplies: 1Last Post: 01-04-2010, 01:38 AM -
String array for Choice, JOptionPane doesn't show
By themburu in forum Java AppletsReplies: 5Last Post: 05-29-2008, 01:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks