掲示板

How to generate PDF from JRXML on button click of JSP

8年前 に Nathan Harrell によって更新されました。

How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
I have a requirement to provide report generation functionality on a button click. I am using Liferay Portal 6.1 with Tomcat 7 as web portal, Liferay Developer Studio (Eclipse Indigo) IDE, iReport (to create report template), and JasperReports library to produce the PDF. The portal is a ticket management system with two entities (Tickets and Documents) which are entered via their respective custom portlets. Both entities, when in edit mode, need the 'View Report' function. I have searched for answers to this problem extensively, picking up a snippet here and there, but nothing I have found is exactly my situation. Upon clicking the 'View Report' button, the user needs to be presented with a formatted PDF where the user can then decide to 'Save', 'Print', or 'Close' from. I also need to pass data to the report so information can be retrieved for the entity that is open (i.e., documentId, ticketId, docType, etc.), but this piece can be added later; once I just get a PDF to open.

Not knowing how to go about implementing this, I decided to use a jQuery Modal to open 'viewReport.jsp' page and process the report there. However, this approach yields a JRException IllegalState: cannot obtain OutputStream because writer is already in use. I have read in my searches that Liferay layout uses OutputStream and that's probably why the writer is already in use. Here's the code I am using:

edit_document.jsp (button and jQuery Modal):
<!-- View Report Button at bottom of form -->
<aui:button type="button" id="viewReportBtn" value="View Report" />



<!-- URL declaration for PDF popup window -->
<portlet:renderURL var="viewReportURL" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>" >
<portlet:param name="mvcPath" value="/html/document/viewReport.jsp" />
<portlet:param name="documentId" value="<%= Long.toString(documentID) %>" />
<portlet:param name="ticketId" value="<%= Long.toString(ticketID) %>: />
<portlet:param name="docType" value="<%= docType %>" /> <!-- This is already a String value -->
</portlet:renderURL>


<!-- jQuery to open popup window for PDF -->
<aui:script use="aui-dialog, aui-overlay-manager, dd-constrain" >

var reportDialogOptions = {
title : 'Dialog',
bodyContent : '',
centered : true,
group : default,
height : 800,
width : 1000,
modal : true,
};


$('#viewReportBtn').on('click', finction(event) {
var editFeelingDialog = new A.Dialog(
A.merge(reportDialogOptions, {
title : 'Document View Report'
})
).plugin(A.Plugin.IO,{uri : '<%= viewReportURL %>'}).render();
});

</aui:script>


viewReport.jsp (page to process jrxml template and open PDF):
<!-- viewReport.jsp page to render PDF -->
<%@ page contentType = "application/pdf" %>

<%@ page trimDirectiveWhitespaces = "true" %>

<%@ page import = "net.sf.jasperreports.engine.*" %>

<%@ page import = "java.io.File" %>
<%@ page import = "java.io.FileInputStream" %>
<%@ page import = "java.io.FileNotFoundException" %>
<%@ page import = "java.io.InputStream" %>

<%@ page import = "java.sql.Connection" %>
<%@ page import = "java.sql.SQLException" %>

<%

Connection conn = null;

try
{
String url = "jdbc:oracle:thin:@myDBSRV:1521:myDatabase";
String userName = "myUsername";
String password = "myPassword";

// Connecting to the Oracle database
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);

// Loading the Jasper Report file from local file system\
String jrxmlFile = session.getServletContext().getRealPath(request.getContextPath())+"\\report5.jrxml";
InputStream input = new FileInputStream(new File(jrxmlFile));

// Generate the report
JasperReport jasperReport = JasperCompileManager.compileReport(input);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPrint, null, conn);

// Export the report as a PDF
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

}
catch (FileNotFoundExcecption ex)
{
System.out.println(ex.getMessage());
ex.printStakeTrace();
}
catch (JRException ex)
{
System.out.println(ex.getMessage());
ex.printStakeTrace();
}
catch (ClassNotFoundException ex)
{
System.out.println(ex.getMessage());
ex.printStakeTrace();
}
catch (SQLException ex)
{
System.out.println(ex.getMessage());
ex.printStakeTrace();
}
finally
{
if (conn != null)
{
conn.close();
}
}

%>

I also tried to add java methods to my DocumentPortlet.java class and call the method(s) when the button is clicked, but I am not that familiar enough with ajax to get it right:
DocumentPortlet.java
public class DocumentPortlet extends MVCPortlet{

Connection conn = null;

public void generateReport()
{

initConnection();
showReport();

}

public void initConnection()
{

String host = "jdbc:oracle:thin:@myDBSRV:1521:myDatabase";
String userName = "myUserName";
String password = "myPassword";

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}

try
{
conn = DriverManager.getConnection(host, userName, password);
}
catch (SQLException ex)
{
ex.printStackTrace();
}

}



public void showReport()
{

//Path to your .jrxml file
String reportName = "[path to file]";

//Get a stream to read the file
InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

try
{
//Fill the report with parameter, connection, and stream reader
JasperPrint jp = JasperFillManager.fillReport(is, null, session);

//Viewer for Jasper report
JRViewer jv = new JRViewer(jp);

//Insert viewer to a JFrame to make it showable
JFrame jf = new JFrame();
jf.getContentPane().add(jv);
jf.validate();
jf.setVisible(true);
jf.setSize(new Dimension(800, 600));
jf.setLocation(300, 100);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
catch (JRException ex)
{
ex.printStakeTrace();
}
finally
{
closeSession(session);
}

}

}

I don't think I am going about this correctly. From what I have been able to find out, I should probably be using serveResource() in my portlet class. How can I provide this functionality in a way that my users can click the button and a PDF be generated on their screen; not a link to the PDF or a PDF that is stored on the file system? I need a clear and concise solution to this problem. Thank you!

Lee
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Nathan Harrell:
I don't think I am going about this correctly.


You can say that again.

This should be implemented as part of a resource request. Resource requests can feed a binary stream back to the browser and do not have the whole portal frame to deal with.

You cannot write your resource request handler in JSP, you'd have to build it into your java portlet code. Inside the implementation of the handler, you can use jasper to generate the PDF and feed back the stream just like you might do in a servlet implementation.

On the JSP side you'll have a resource url that will point to your portlet's resource handler and may need to tinker with things to figure out when to invoke to display the pdf.
8年前 に Nathan Harrell によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
Mr. Nebinger,

Thank you for your speedy response! I will do processing of the JRXML and handle the resource request in my DocumentPortal java class and invoke the resourceURL in the JSP on a button click event!

Regards,

Lee
8年前 に Nathan Harrell によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
Obviously, I am not grasping the concept here. I have changed things up in:
edit_document.jsp
<aui:button type="button" id="viewReportBtn" value="View Report" />


<portlet:resourceURL id="generatePDF" var="generateReportURL" >
<portlet:param name="jspPage" value="/html/document/edit_document.jsp" />
<portlet:param name="documentId" value="<%= Long.toString(documentID) %>" />
<portlet:param name="ticketId" value="<%= Long.toString(ticketID) %>" />
<portlet:param name="docType" value="<%= docType %>" />
</portlet:resourceURL>


<aui:script>
$(document).ready(function()
{
$('#viewReportBtn').click(function(event){
$.ajax('<%= generateReportURL %>');
});
});


And I created a resourceRequestHandler in:
DocumentPortlet.java
@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException
{
String url = "jdbc:oracle:thin:@myDBSrv:1521:myDatabase";
String user = "myUser";
String pass = "myPassword";
Connection conn;
try
{
// Connect to database
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, pass);

// Load the Jasper Report file from local file system
String jrxmlFile = "C:\\NICS_Portal\\liferay-plugins-sdk-6.1.20\\portlets\\documents-portlet" +
"\\documents-portlet\\report5.jrxml";
InputStream input = new FileInputStream(new File(jrxmlFile));

// Generate the report
JasperReport jasperReport = JasperCompileManager.compileReport(input);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);

// Export the report to PDF format
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
OutputStream os = resourceResponse.getPortletOutputStream();
resourceResponse.setContentType("application/pdf");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os);
exporter.exportReport();
os.flush();
}
catch (FileNotFoundException ex)
{
System.out.println("File not found on file system, check file path!" + ex.getMessage());
ex.printStackTrace();
}
catch (JRException ex)
{
System.out.println("Error creating Jasper Report!" + ex.getMessage());
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
System.out.println("Oracle Class for driver not found!" + ex.getMessage());
ex.printStackTrace();
}
catch (SQLException ex)
{
System.out.println("Error getting connection to database!" + ex.getMessage());
ex.printStackTrace();
}

super.serveResource(resourceRequest, resourceResponse);

}


Everything works fine up until actually exporting the PDF in the OutputStream; I still get this IllegalStateException:
StackTrace:
Apr 30, 2015 7:57:37 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
at com.liferay.portlet.MimeResponsImpl.getWriter(MimeResponseImpl.java:82)
at com.liferay.porlet.PortletServletResponse.getWriter(PortletServletResponse.java:207)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:324)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:353)
at org.apache.jsp.html.document.edit_005document_jsp._jspService(edit_005document_jsp.java:295)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portlal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portlal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portlal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at com.liferay.porlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:323)
at com.liferay.porlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:105)
at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:367)
at com.liferay.util.bridges.mvc.MVCPortlet.serveResource(MVCPortlet.java:235)
at gov.nasa.nics.portlet.DocumentPortlet.serveResource(DocumentPortlet.java:312)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:531)
at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:626)
at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:436)
at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:1075)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:719)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:176)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:560)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:537)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.BaseFilter.processFilter(BaseFilter.java:163)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
at com.liferay.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:239)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:306)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
at com.liferay.portlal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValue.invoke(StandardWrapperValue.java:225)
at org.apache.catalina.core.StandardContextValue.invoke(StandardContextValue.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValue.invoke(StandardHostValue.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http1.AbstractHttp1Processor.process(AbstractHttp1Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExcutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExcutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Please help I really need this PDF to display!!
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP (回答)

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Your issue is that you've generated the PDF into the stream but at the bottom of the file you have:

super.serveResource(resourceRequest, resourceResponse);


By calling the super class it is trying to write it's own stuff into the stream. Take out this line and you'll be just fine.
8年前 に Nathan Harrell によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
You are, of course, correct! Thanks so much!! removing that call did stop the IllegalStateException, however, I also didn't get a PDF opened up. Is there something missing in the code that will present the PDF in the viewer so my users can save or print?
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
The stream is being returned. I think your ajax call needs some help, though.

You'll be given back the PDF data, but then you'd have to get the browser to render it.

Normally you'd do this by just including an <a /> link with the resource URL and a _blank target to open the result in a new tab, but I'm not sure what your plan for rendering might be.
8年前 に Nathan Harrell によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
Very good information! What I want is to have the PDF display in a popup when the button is clicked. I wrongly assumed that exporter.exportReport() would deliver the PDF back with the JasperReports Viewer; don't ask me why I assumed that! Inexperience, I suppose. So I changed my resourceURL to point to the view_report.jsp I originally was using and modified my aui:script like so:

edit_document.jsp:
<portlet:resourceURL id = "generatePDF" var = "generateReportURL" >
<portlet:param name = "jspPage" value = "/html/document/view_report.jsp" />
<portlet:param name = "documentId" value = "<%= Long.toString(documentID) %>" />
<portlet:param name = "ticketId" value = "<%= Long.toString(ticketID) %>" />
<portlet:param name = "docType" value = "<%= docType %>" />
</portlet:resourceURL>

<aui:script use = "aui-dialog, aui-overlay-manager, dd-constrain" >

var reportDialogOptions = {
title : 'Dialog',
bodyContent : '',
centered : true,
group : 'default',
height : 800,
width : 1000,
modal : true,
}


$(#'viewReportBtn').click(function(event){

var reportDialog = new A.Dialog(
A.merge(reportDialogOptions, {
title: 'Document View Report'
})
).plug(A.Plugin.IO, {uri : '<%= generateReportURL %>'}).render();
});

<aui:script>

The end result is actually data being displayed in the modal window, however, it is not what I was expecting....see attached PDF (I had to get this from the actual system I am using; which is a system I cannot retrieve data from). And sir, you have been a HUGE help!!

添付ファイル:

6年前 に om prakash によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 18 参加年月日: 14/07/09 最新の投稿
Hi Nathan,

Could you please post the source code here. I am also need to integrate jasper report by button click !emoticonemoticon

Thanks in adnvance !
8年前 に Nathan Harrell によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

New Member 投稿: 6 参加年月日: 12/11/19 最新の投稿
David H Nebinger:
The stream is being returned. I think your ajax call needs some help, though.

You'll be given back the PDF data, but then you'd have to get the browser to render it.

Normally you'd do this by just including an <a /> link with the resource URL and a _blank target to open the result in a new tab, but I'm not sure what your plan for rendering might be.


Can you expand on the <a/> link with resource URL and a _blank target concept please?
thumbnail
8年前 に Jack Bakker によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
In Vaadin, we write to temp file, and then open it in new window


			File file = new File(filePath);
			if ("csv".equals(outputType)) {
				JRCsvExporter exporter = new JRCsvExporter();
				exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);

				exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file);
				exporter.exportReport();
				getMainWindow().open(new FileResource(file, this));
			} else if ("pdf".equals(outputType)) {
				JasperExportManager.exportReportToPdfFile(print, filePath);

				getMainWindow().open(new FileResource(file, this), "_blank",
						1000, 800, 0);
			}
			file.deleteOnExit();
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: How to generate PDF from JRXML on button click of JSP

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Ew, Jack, you know you can output directly to the stream w/o the temp file?