Jasper Report PDF does not open - java

I am trying to build a sample web application which loads a pdf report generated through jasper reports (.jasper file). However the report does not open as a pdf with the message "This PDF document might not be displayed correctly".
The code snippets are as below. There is no exception log coming in the server log. Any help would be great. Thanks.
Servlet Controller Class
#WebServlet("/generateReport")
public class JasperReportsExample extends HttpServlet{
final String deviceJasper = "SampleReport.jasper";
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("application/pdf");
response.setCharacterEncoding("UTF-8");
try{
List<SampleReportBean> sampleReportBeanList = new ArrayList<SampleReportBean>();
SampleReportBean bean = new SampleReportBean();
bean.setName("Hello");
sampleReportBeanList.add(bean);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(deviceJasper);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(is);
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(sampleReportBeanList);
Map<String, Object> parameters = new HashMap<String, Object>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanCollectionDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, deviceJasper);
}catch(Exception e) {
System.out.println("Error:while creating jasper report....");
e.printStackTrace();
}
}
}
html page
<form action="/samplejasperreport/generateReport" method="get">
<div>
<input type="submit" name="Generate Report" value="Generate Report">
</div>
</form>
SampleReport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="SampleReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="038b20ef-43f5-4f05-8318-627e403a7110">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JavaBean Adapter"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="31" splitType="Stretch">
<textField>
<reportElement x="150" y="0" width="140" height="30" isPrintWhenDetailOverflows="true" uuid="f6eec303-affe-4804-bb6a-e5c07516a46f"/>
<textElement textAlignment="Center">
<font size="22"/>
</textElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="1" splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Directory structure image
Error screen:

Thanks to AlexK:
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());//send the pdfstream to the browser

Related

Jasper report blank page

My jrxml and java code below . I am trying to create report with some text and values . However blank report is generated . I am pasing map to fill the report as parameter . I have to add 4-5 static lines and then one dynamic variable . I have added these thing in detailed band .whats wrong
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="Untitled_report_2"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<field name="Field" class="java.lang.String"/>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="50" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="50" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="30" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="100" isSplitAllowed="true" >
<staticText>
<reportElement
x="20"
y="10"
width="180"
height="30"
key="staticText-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="20"
y="40"
width="60"
height="20"
key="textField-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Field}]]></textFieldExpression>
</textField>
<staticText>
<reportElement
x="20"
y="70"
width="160"
height="30"
key="staticText-2"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="30" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</pageFooter>
<lastPageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</lastPageFooter>
<summary>
<band height="50" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
Java code :
InputStream fileInput = getApplicationContext().getResource("/WEB-INF/reports/myjrxml.jrxml").getInputStream();
JasperReport jasperReport = JasperCompileManager.compileReport(fileInput);
HashMap map = new HashMap();
map.put("Field", "test");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map);
byte[] output1 = JasperExportManager.exportReportToPdf(jasperPrint);
String filename = "d:/test.pdf";
FileOutputStream fo = new FileOutputStream(filename);
fo.write(output1);
fo.close();
You are confusing the report data with parameters. I don't see that you have any report data, which is why you are getting an empty report. Further, you are filling a parameter named "Field" instead of the actual report data. So you either need to create a parameter called "Field" in your report, and then refer to it in the detail band, OR you need to pass the report data into your report something like
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(dataSet);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, data);
where dataSet is a collection, such as List<?>. Within the List, you would have an object where one of the properties is Field.
I had also blank page (pdf). Even for the simplest report.Until I sent empty datasource (new JREmptyDataSource())!
This solved my problem:
Map<String, Object> param = new HashMap<>();
param.put("SOME_PARAM","something");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());
Explanation here.
By default, when no datasource info is present in a report, JR generates no pages.

Jasper generated Excel file error "Excel found unreadable content in .. "

I'm using Java and Jasper to generate reports in .xlsx format.
And I was successful and I have components in my application which create actual reports with data.
recently I was trying to add another component and the report generation was successful , but the generated .xslx file wont open with MS Excel or any other.
the code parts are below.
ArrayList<ReportBean> reportBean = new ArrayList<ReportBean>();
response.setHeader("Content-Disposition", "attachment;filename=BudgetaryQuote.xlsx");
response.setContentType("application/xlsx");
OutputStream outStream = response.getOutputStream();
Report report = new Report(template, "xlsx", reportBean, outStream);
//Report(String template, String format, ArrayList dataList,OutputStream outputStream)
report.generateReport();
in generateReport() it has ,
InputStream inputStream = new FileInputStream(new File(this.template));
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList);
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
if(this.format.equalsIgnoreCase(XLSX)) {
JRXlsxExporter Xlsxexporter = new JRXlsxExporter();
Xlsxexporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
Xlsxexporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
Xlsxexporter.exportReport();
}
the .jrxml file (It's pretty much blank)
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="timeSheetDetailedReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4ffef809-ea2d-4533-a0b9-bdd2d055afbe">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
There is an error like in the image.
"Excel found unreadable content in filename.xls. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."
How can I check what is the wrong with the file ?
I just solved the problem. But it's not clear.
my code had the below code ,
ArrayList<ReportBean> reportBean = new ArrayList<ReportBean>();
Report report = new Report(template, "xlsx", reportBean, outStream);
report.generateReport();
The problem was the ArrayList reportBean was empty. The I add an dummy ReportBean to the list and the problem was solved.
But I have no idea how it solved the problem and why

JasperReport API: createReport returns null because of html component

I have a problem with JasperReports API.
I add html component into my report (via iReport designer 5.0.4). Compilation to jasper file runs without errors.
When I try create the report I get null from JasperPrint object (method createReport(getReportAsByteArray(), parameters, dataSource); returns null instead of JasperPrint object.
getReportAsByteArray() - returns jasper report file from my database).
The Html component (in iReport) is connected with string parameter, I put right string parameter into parameters HashMap<>. I already have tried write html text in html content exp. (html component properties).
It didn't work.
Earlier everything was fine, when the jasper file was without html component I could create my report and export to PDF.
Now I can see the resulting report (with html component) in my iReport preview (and it works), but when I fill my report via my java bean - it doesn't work.
(the jasper file with only one object - html component - didn't work too).
jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="raport_test_1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5a918503-735f-4812-bbd1-f4017cca4b0f">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="TEXT_CONTENT" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="e9907391-3e2f-45c9-af15-b7a60f7a3312" x="0" y="0" width="555" height="125"/>
<hc:html xmlns:hc="http://jasperreports.sourceforge.net/htmlcomponent" xsi:schemaLocation="http://jasperreports.sourceforge.net/htmlcomponent http://jasperreports.sourceforge.net/xsd/htmlcomponent.xsd" scaleType="RealSize" horizontalAlign="Left" verticalAlign="Middle">
<hc:htmlContentExpression><![CDATA[$P{TEXT_CONTENT}]]></hc:htmlContentExpression>
</hc:html>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
And the method, which should return byte array of report pdf file
Map<String, Object> parameters = new HashMap<>();
parameters.put("TEXT_CONTENT","sample text<br/>");
List<Data> list= getList();
if (list == null) {
list = new ArrayList<>();
}
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(list);
JasperPrint printableReport = createReport(getReportFileAsByteArray(), parameters, dataSource);
if (printableReport != null) {
try {
return JasperExportManager.exportReportToPdf(printableReport);
} catch (JRException ex) {
//
}
}
return null;
Thanks for any advices!

JR report doesn't show data

I have written this code to show a simple report using iReport 4.7.1.
private void printReport() {
try {
JRTableModelDataSource dataSource = new JRTableModelDataSource(
new JTable().getModel());
String reportSource = "C:\\Reports\\report1.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
params.put("Name", "SriLanka");
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {
e.printStackTrace();
}
}
Here are my libraries:
commons-beanutils-1.8.0.jar
commons-collections-2.1.1.jar
commons-digester-2.1.jar
commons-logging-1.1.1.jar
jasperrreports-4.7.1.jar
jasperreports-applet-4.7.1.jar
jasperreports-javaflow-4.7.1.jar
groovy-all-1.7.5.jar
and NetBeans output shows this warning
Oct 08, 2012 2:57:31 PM net.sf.jasperreports.engine.component.ComponentsEnvironment findBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
and here is the .jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5174594e-de3c-4b09-932b-c6665bf6a34b">
<parameter name="Name" class="java.lang.String" isForPrompting="false"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement uuid="fd02a8bc-548b-41c1-aed5-2a7c2e257704" x="210" y="23" width="157" height="36"/>
<textElement>
<font size="18"/>
</textElement>
<textFieldExpression><![CDATA[$P{Name}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The report opens but doesn't show any text.
To solve this problem you should:
check your datasource, it can be empty;
add textFields elements with fields expressions (<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>) to the Detail band to show records in report.
Anyway your parameter Name should be displayed in the Title band (in generated report). You can pass even the JREmptyDataSource to check this.
For showing data you can chose one of this ways:
1. Using Detail band
It is classical, "old school" method for showing data stored in records from the data source. The JR engine iterates through the data source for rendering this section. With help of textField elements we can show the fields values.
The sample: look at $jasperreports$\demo\samples\jasper sample from JR distribution package.
2. Using Crosstab component
The Crosstab component used for summarizing data into grid which has two dimensions.
The sample: look at $jasperreports$\demo\samples\crosstabs sample.
3. Using List component
The List component iterates on set of its records (defined with help of subDataset property).
The sample: look at Using the Built-in List Component sample.
4. Using Table component
The Table is using for showing data with tabular structure. As a List component has its own subDataset.
The sample: look at Using the Built-in Table Component sample.
4. Using Subreport component
The Subreport is using for building complex reports such as compilation of different reports in one. This component often operates with subqueries.
The sample: look at Subreports sample.
You can read details in JasperReports Ultimate Guide

PrimeFaces and JasperReports

i'm trying to develop a web app for reporting, and have built a site with EJB3 + primefaces already. Now i'm head aching how to integrate Jasperreport into primefaces... I found no guide or discussion about this topic, I wonder is it not possible? or actually it is not a right way to do? I'm actually quite new to develop JavaEE6, dont plan to use frameworks like spring and seam yet.
model
#Stateless
#LocalBean
public class BookEJB {
// #Override
public void printReport() throws ClassNotFoundException, IOException, JRException, SQLException {
Connection connection;
Map parameterMap = new HashMap();
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx
.getExternalContext().getResponse();
InputStream reportStream = ctx.getExternalContext()
.getResourceAsStream("reports/report1.jasper");
ServletOutputStream servletOutputStream = response.getOutputStream();
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/bookdb?user=root&password=******");
ctx.responseComplete();
response.setContentType("application/pdf");
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, connection);
connection.close();
servletOutputStream.flush();
servletOutputStream.close();
}
}
Controller
#ManagedBean(name = "bookCtrl")
#RequestScoped
public class BookController {
#EJB
private BookEJB bookEJB;
public void doPrintReport() throws ClassNotFoundException, IOException, JRException, SQLException {
bookEJB.printReport();
}
}
view (JSF)
<body>
<f:view>
<h:outputText value="Click on the link below to generate the report." />
<h:form>
<h:commandButton action="#{bookCtrl.doPrintReport}" value="Generate Report" />
</h:form>
</f:view>
</body>
Jasper
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="SQL">
<![CDATA[SELECT
*
FROM
`book` book]]>
</queryString>
<field name="Id" class="java.lang.Integer"/>
<field name="title" class="java.lang.String"/>
<field name="price" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="45" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="21" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Id]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[title]]></text>
</staticText>
<staticText>
<reportElement x="200" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[price]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="24" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{Id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{title}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{price}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The error occurred when I click the button of JSF, below log is from glassfish
WARNING: A system exception occurred during an invocation on EJB BookEJB method public void blah.BookEJB.printReport() throws java.lang.ClassNotFoundException,java.io.IOException,net.sf.jasperreports.engine.JRException,java.sql.SQLException
javax.ejb.EJBException.....
SEVERE: javax.ejb.EJBException
javax.faces.el.EvaluationException: javax.ejb.EJBException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
WARNING: #{bookCtrl.doPrintReport}: javax.ejb.EJBException
javax.faces.FacesException: #{bookCtrl.doPrintReport}: javax.ejb.EJBException...
Caused by: javax.faces.el.EvaluationException: javax.ejb.EJBException...
SEVERE: javax.faces.FacesException: #{bookCtrl.doPrintReport}: javax.ejb.EJBException...
Caused by: javax.faces.FacesException: #{bookCtrl.doPrintReport}: javax.ejb.EJBException...
Caused by: javax.faces.el.EvaluationException: javax.ejb.EJBException...
Caused by: javax.ejb.EJBException...
Caused by: java.lang.NullPointerException...
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response.....
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response.....
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response.....
Have you tried using the p:fileDownload component inside your commandLink?
See:
http://www.primefaces.org/showcase/ui/fileDownload.jsf
That way, instead of messing around with responseComplete or having to make a separate servlet, you just have another controller/managed bean method that returns an instance of StreamedContent (primefaces class).
You are modifying the response after "responseComplete()". Calling "responseComplete()" should be the last thing you do.
Best way to deal with jasper-methods is to disable ajax in the commandButton/commandLink. Thats how it is possible to stay with the Jasper-conversion.
<p:commandButton title="EK Preview" icon="fa fa-file-pdf-o" actionListener="#{ctrlFiDoc.doReport_PC}" ajax="false"/>
There is no need to stay strictly to the p:fileDownload-element if its not necessary.
Probably this line is causing the issue:
InputStream reportStream = ctx.getExternalContext()
.getResourceAsStream("reports/report1.jasper");
See this question

Categories

Resources