0

how to show jasper report?

asked 2015-02-26 03:47:33 +0800

jwasky gravatar image jwasky
11 3

i have report.jasper and report.jrxml in my project, how to show this file, if i use button to show this file? help me please

delete flag offensive retag edit

Comments

if i use netbeans 7.1, can i use this sourcecode?

jwasky ( 2015-02-26 07:48:56 +0800 )edit

thank you Senthilchettyin, this is your blog http://emrpms.blogspot.com/2013/09/create-report-with-zk-using-ireport-510.html right

jwasky ( 2015-02-26 08:28:09 +0800 )edit

Yes Yes Yes

Senthilchettyin ( 2015-02-26 12:47:55 +0800 )edit

i have some error SEVERE: >>net.sf.jasperreports.engine.JRRuntimeException: Unknown hyperlink target 0 >> at net.sf.jasperreports.engine.JRHyperlinkHelper.getLinkTarget(JRHyperlinkHelper.java:273), can you help me? i use jasperreport 3.7.0. jar and ireport 5.6.0 , maybe if this is the cause?

jwasky ( 2015-02-27 02:31:09 +0800 )edit

and i use neatbeans 7.1.1

jwasky ( 2015-02-27 02:46:58 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-02-26 06:26:07 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2619 3 8
http://emrpms.blogspot.in...

Here is the Stuff

    public class GenerateReport {
protected Map<String, Object> params = new HashMap<String, Object>();
protected String reportFile;
protected String tempPrefix;
protected Iframe reportFrame;
protected JasperPrint jasperPrint = null;
protected Boolean reportDone = false;
protected String pdfFileName;
protected String moreErrorInfo;
protected Boolean useVirtualizer = false;
protected Component PDFViewerContainer = null;
protected String reportViewerFileName;
private boolean showInNewWindow = false;

public boolean isShowInNewWindow() {
    return showInNewWindow;
}

public void setShowInNewWindow(boolean showInNewWindow) {
    this.showInNewWindow = showInNewWindow;
}

public String getReportViewerFileName() {
    return reportViewerFileName;
}

public void setReportViewerFileName(String reportViewerFileName) {
    this.reportViewerFileName = reportViewerFileName;
}

public Component getPDFViewerContainer() {
    return PDFViewerContainer;
}

public void setPDFViewerContainer(Component pDFViewerContainer) {
    PDFViewerContainer = pDFViewerContainer;
}

public Boolean getUseVirtualizer() {
    return useVirtualizer;
}

public void setUseVirtualizer(Boolean useVirtualizer) {
    this.useVirtualizer = useVirtualizer;
}

public String getMoreErrorInfo() {
    return moreErrorInfo;
}

public void setMoreErrorInfo(String moreErrorInfo) {
    this.moreErrorInfo = moreErrorInfo;
}

public String getPdfFileName() {
    return pdfFileName;
}

public void setPdfFileName(String pdfFileName) {
    this.pdfFileName = pdfFileName;
}

public Boolean getReportDone() {
    return reportDone;
}

public void setReportDone(Boolean reportDone) {
    this.reportDone = reportDone;
}

public Iframe getReportFrame() {
    return reportFrame;
}

public void setReportFrame(Iframe reportFrame) {
    this.reportFrame = reportFrame;
}

public String getTempPrefix() {
    return tempPrefix;
}

public void setTempPrefix(String tempPrefix) {
    this.tempPrefix = tempPrefix;
}

public String getReportFile() {
    return reportFile;
}

public void setReportFile(String reportFile) {
    this.reportFile = reportFile;
}

public Map<String, Object> getParams() {
    return params;
}

public void setParams(Map<String, Object> params) {
    this.params = params;
}


public <T> void generateReportByJavaList2(List<T> listValues) {
    this.jasperPrint = null;
    File temp;
    try {
    temp = File.createTempFile(this.tempPrefix, ".pdf");
    this.jasperPrint = JasperFillManager.fillReport(this.reportFile,
        this.params, new JRBeanCollectionDataSource(listValues,
                            false));
    JasperExportManager.exportReportToPdfFile(jasperPrint,
            temp.getAbsolutePath());
    this.reportViewerFileName = "reportViewer.zul";
    Window win = (Window) Executions.createComponents(
            this.reportViewerFileName, PDFViewerContainer, null);
    this.reportFrame = (Iframe) win.getFellow("reportframe");
    File f = new File(temp.getAbsolutePath());
    byte[] buffer = new byte[(int) f.length()];
    FileInputStream fs = new FileInputStream(f);
    fs.read(buffer);
    fs.close();

    ByteArrayInputStream is = new ByteArrayInputStream(buffer);
    AMedia amedia = new AMedia(temp.getAbsolutePath(), "pdf",
                    "application/pdf", is);
    this.reportFrame.setContent(amedia);

    } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
}

}





Example Usage 

private void generatePDFReport() {

String reportFile = Executions.getCurrent().getDesktop().getWebApp()
        .getRealPath("/reports");
reportFile = reportFile + "/jraccountlist.jasper";
Map<String, Object> params = new HashMap<String, Object>();
params.put("pPracticeName", FHSessionUtil.getLabPractice().getName());
params.put("pReportTitle", "Account List");
GenerateReport myreport = new GenerateReport();
myreport.setParams(params);
myreport.setReportFile(reportFile);
myreport.setTempPrefix("AccountList");
myreport.generateReportByJavaList(accountList);
}
link publish delete flag offensive edit
0

answered 2015-02-26 06:27:21 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2619 3 8
http://emrpms.blogspot.in...

reportViewer.zul

<window   width="100%" height="100%" title="PDF-Viewer"
    border="normal" minimizable="false"  maximizable="false"
    sclass="mymodal" closable="true" apply="org.zkoss.bind.BindComposer">
    <iframe height="100%" width="100%" id="reportframe"></iframe>
</window>
link publish delete flag offensive edit
0

answered 2015-02-26 06:28:29 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2619 3 8
http://emrpms.blogspot.in...

Maven

<!-- Jasperreports -->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>5.6.1</version>
    </dependency>
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-02-26 03:47:33 +0800

Seen: 35 times

Last updated: Jun 21

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More