在我的Liferay的JSF

在我的Liferay的JSF

本文介绍了在我的Liferay的JSF Portlet中显示pdf时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我将liferay 5.2与jsf-portlet一起使用.

I use liferay 5.2 with jsf-portlet.

我要从页面中按一个按钮来生成一个PDF.在Managedbean中,我构建了pdf,并且希望在响应中显示它.

From the page I want to press a button to generate one PDF.In managedbean i build pdf and I want to show it in response.

在名为outputStreamByteArrayOutputStream中,我使用JasperReport构建了pdf.

In a ByteArrayOutputStream named outputStream i have my pdf built with JasperReport.

我写:

   PortletResponse portletResponse = (PortletResponse)externalCtx.getResponse();
   HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(portletResponse);

   ServletOutputStream out = httpResponse.getOutputStream();
   String filename="Pdf" + System.currentTimeMillis()+".pdf";
   httpResponse.reset();

   httpResponse.setContentType("application/pdf");
   httpResponse.setHeader("Content-Disposition", "attachment; filename=\""+ filename + "\"");
   httpResponse.setContentLength(outputStream.size());

   outputStream.writeTo(out);

   out.flush();
   out.close();

我看不到任何输出!在jboss日志中,我读到:IllegaStateException ....

I do not see anything output! In jboss log i read: IllegaStateException....

怎么了?

日志

        11:03:19,716 INFO  [STDOUT] 11:03:19,716 ERROR [IncludeTag] Current URL /web/organo-di-governo/datawarehouse?p_p_id=1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_count=1&_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_com.sun.faces.portlet.VIEW_ID=%2Fview.xhtml&_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_com.sun.faces.portlet.NAME_SPACE=_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_ generates exception: null
                11:03:19,717 INFO  [STDOUT] 11:03:19,717 ERROR [IncludeTag] java.lang.IllegalStateException
                    at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
                    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
                    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
                    at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:326)
                    at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342)
                    at org.apache.jasper.runtime.JspWriterImpl.print(JspWriterImpl.java:468)
                    at com.liferay.taglib.util.ThemeUtil.includeVM(ThemeUtil.java:208)
                    at com.liferay.taglib.util.ThemeUtil.include(ThemeUtil.java:68)
                    at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:59)
                    at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_liferay_002dtheme_005finclude_005f1(portal_jsp.java:816)
                    at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_c_005fotherwise_005f0(portal_jsp.java:788)
                    at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:724)
                    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
                    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                11:03:19,718 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
                java.lang.IllegalStateException



        11:03:19,719 ERROR [[Main Servlet]] Servlet.service() for servlet Main Servlet threw exception
        java.lang.IllegalStateException
            at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
            at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
            at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)



        11:03:19,722 INFO  [STDOUT] 11:03:19,720 ERROR [OpenSSOFilter] org.apache.jasper.JasperException: java.lang.IllegalStateException
        org.apache.jasper.JasperException: java.lang.IllegalStateException
            at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:409)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)




        11:03:19,722 INFO  [STDOUT] n.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


        Caused by: java.lang.IllegalStateException
            at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
            at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
            at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)

推荐答案

唯一可行的方法是使用JSR-286规范的"RESOURCE"阶段.当前,在您的代码中,您处于"RENDER"阶段,该阶段仅允许"text/html"编码.

The only appropriate way to do this is by using the "RESOURCE" phase of the JSR-286 spec. Currently in your code you are in "RENDER" phase which is forcefully only allows "text/html" encoding.

在普通的JSP中,标记看起来像:

In plain JSP, the tag would look something like:

<portlet:resourceURL id="/super-cool.pdf" />

然后在您的Portlet类中,实现serveResource(ResourceRequest req,ResourceResponse res)方法,并读取调用ResourceRequest的req.getResourceId()方法,然后行为调用您的业务逻辑(创建PDF),然后将其写入到输出流.

Then in your portlet class you implement the serveResource(ResourceRequest req, ResourceResponse res) method and read call the req.getResourceId() method of the ResourceRequest and behave invoke your business logic (create your PDF) and subsequently write it to the output stream.

在JSF中,我不确定是否甚至支持该方法,这意味着唯一的方法是将任务委托给servlet调用.在JSF中查看是否实现了JSR-286资源处理.

In JSF, I'm not entirely sure if this is even supported, which means that the only way would be to delegate the task to a servlet call. Look in JSF to see if JSR-286 Resource handling is implemented.

这篇关于在我的Liferay的JSF Portlet中显示pdf时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:45