0

我目前正在使用 Icefaces 1.8.2、JSF 1.1、JasperReports 4.5.1 和 weblogic 10.3.2 我尝试在单击 excel 图像时创建一个功能,它将尝试使用 Jasper Report 将结果获取到 excel 文件中。我可以编译以下代码。

public String downloadToExcel(javax.faces.event.ActionEvent event)
{
    InputStream reportStream = null;
    try
    {

        FacesContext context = FacesContext.getCurrentInstance();  
        ExternalContext ext = context.getExternalContext();  
        //reportStream = ext.getResourceAsStream("resources/jasper/PreviousBookings.jasper"); 
        reportStream = JRLoader.getResourceInputStream("resources/jasper/PreviousBookings.jasper");
        //JasperReport jasperReport = JasperCompileManager.compileReport(fis);
        Object[] previousBooking = new Object[newOpportunityByPreviousBookingDTOList.size()];
        int i = 0;
        for(NewOpportunityDTO previousBookingDTO:newOpportunityByPreviousBookingDTOList)
        {
            previousBooking[i] = previousBookingDTO;
            i++;
        }

        /*
        reportStream = JRLoader.getResourceInputStream("resources/jasper/PreviousBookings.jasper");
        JasperPrint jprint1 = JasperFillManager.fillReport(reportStream, new HashMap(), new JRBeanArrayDataSource(previousBooking));
        JRXlsxExporter exporterXLS = new JRXlsxExporter();
        exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jprint1);
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_FILE_NAME, "c:/test1/test.xlsx");
        exporterXLS.exportReport();
        */
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, new HashMap(), new JRBeanArrayDataSource(previousBooking)); 
        HttpServletResponse resp = (HttpServletResponse) ext  
                .getResponse();  

        resp.setContentType("application/vnd.ms-excel");  
        String filename = new StringBuffer("previousBookings").append(  
                ".xls").toString();  
        resp.setHeader("Content-Disposition", "inline;filename="  
                + filename);  

        JExcelApiExporter exporterXLS = new JExcelApiExporter();  

        exporterXLS.setParameter(  
            JRXlsExporterParameter.JASPER_PRINT,  
            jasperPrint);  
        exporterXLS.setParameter(  
            JRXlsExporterParameter.IS_DETECT_CELL_TYPE,  
            Boolean.TRUE);  
        exporterXLS.setParameter(  
            JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,  
            Boolean.FALSE);  
        exporterXLS.setParameter(  
            JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,  
            Boolean.TRUE);  
        exporterXLS.setParameter(  
            JRXlsExporterParameter  
                .IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,  
            Boolean.TRUE);  
         exporterXLS.setParameter(  
        JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,  
         Boolean.TRUE);  
        exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, 
                resp.getOutputStream());  
        exporterXLS.exportReport();
        //byte[] reportPDF = JasperRunManager.runReportToPdf(reportStream, parameterMap, connection); 

        //context.getApplication().getStateManager().saveView(context);  
        context.getApplication().getStateManager().saveSerializedView(context);  
        ServletOutputStream out;
        out = resp.getOutputStream();

        BufferedOutputStream bos = new BufferedOutputStream(out);
        bos.flush();
        bos.close();

        context.responseComplete();  

    }
    catch(Exception e)
    {
        Utility.setTab(AirFreightConstants.AIRFREIGHT_OPPORTUNITIES);
        log.error(StringUtil.exceptionToString(e));
        setErrorMessage("operation.failed.error.message", "Error Detail:"+StringUtil.exceptionToString(e));
        return null;
    }
    return "success";
}

我尝试使用“saveView”,但出现以下错误:

Caused By: java.lang.NoSuchMethodError: javax.faces.application.StateManager.saveView(Ljavax/faces/context/FacesContext;)Ljava/lang/Object;
    at com.cta.web.beans.OpportunitiesBean.downloadToExcel(OpportunitiesBean.java:321)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    Truncated. see log file for complete stacktrace

所以从下面的 url (https://jira.springsource.org/browse/SWF-1112) 它告诉我使用 saveSerializedView 我可以编译但是在执行时得到以下错误:

23:38:22,002 ERROR ViewRootStateManagerImpl:145 - Exception finding JSF1.2 saveView method on delegate
java.lang.NoSuchMethodException: org.apache.myfaces.application.jsp.JspStateManagerImpl.saveView(javax.faces.context.FacesContext)
    at java.lang.Class.getMethod(Class.java:1605)
    at com.icesoft.faces.application.ViewRootStateManagerImpl.initializeParameters(ViewRootStateManagerImpl.java:143)
    at com.icesoft.faces.application.ViewRootStateManagerImpl.saveView(ViewRootStateManagerImpl.java:157)
    at com.icesoft.faces.application.ViewRootStateManagerImpl.saveSerializedView(ViewRootStateManagerImpl.java:193)
    at com.cta.web.beans.OpportunitiesBean.downloadToExcel(OpportunitiesBean.java:322)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:130)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
    at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
    at javax.faces.component.UICommand.broadcast(UICommand.java:89)
    at com.icesoft.faces.component.panelseries.UISeries$RowEvent.broadcast(UISeries.java:633)
    at com.icesoft.faces.component.panelseries.UISeries.broadcast(UISeries.java:295)
    at com.icesoft.faces.component.paneltabset.PanelTabSet.broadcast(PanelTabSet.java:318)
    at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
    at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
    at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:50)
    at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:171)
    at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:112)
    at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:65)
    at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:48)
    at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:58)
    at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:55)
    at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:77)
    at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:55)
    at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:192)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:67)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.fedex.login.filter.WssoAuthenticationFilter.doFilter(WssoAuthenticationFilter.java:188)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

这是JasperReport.jxml

<?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="report3" 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"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1"/>
    <subDataset name="Table Dataset 2"/>
    <field name="awb" class="java.lang.String"/>
    <field name="departureDate" class="java.lang.String"/>
    <field name="destination" class="java.lang.String"/>
    <field name="statusDescription" class="java.lang.String"/>
    <field name="owner" class="java.lang.String"/>
    <field name="comments" class="java.lang.String"/>
    <field name="flight" 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">
            <staticText>
                <reportElement x="6" y="28" width="80" height="30"/>
                <textElement/>
                <text><![CDATA[Departure Date]]></text>
            </staticText>
            <staticText>
                <reportElement x="91" y="28" width="50" height="30"/>
                <textElement/>
                <text><![CDATA[AWB]]></text>
            </staticText>
            <staticText>
                <reportElement x="215" y="28" width="100" height="30"/>
                <textElement/>
                <text><![CDATA[Destination]]></text>
            </staticText>
            <staticText>
                <reportElement x="330" y="28" width="73" height="30"/>
                <textElement/>
                <text><![CDATA[Status]]></text>
            </staticText>
            <staticText>
                <reportElement x="417" y="28" width="54" height="30"/>
                <textElement/>
                <text><![CDATA[Owner]]></text>
            </staticText>
            <staticText>
                <reportElement x="481" y="28" width="73" height="30"/>
                <textElement/>
                <text><![CDATA[Comments]]></text>
            </staticText>
            <staticText>
                <reportElement x="145" y="28" width="50" height="30"/>
                <textElement/>
                <text><![CDATA[Flight]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="7" y="13" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{departureDate}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="92" y="13" width="50" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{awb}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="145" y="15" width="50" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{flight}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="211" y="17" width="100" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{destination}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="332" y="13" width="72" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{statusDescription}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="418" y="15" width="54" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{owner}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="482" y="13" width="100" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{comments}]]></textFieldExpression>
            </textField>
        </band>
        <band height="50"/>
        <band height="50"/>
        <band height="50"/>
        <band height="50"/>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>
4

1 回答 1

1

该方法是在 JSF 1.2 中引入的,因此在 JSF 1.1 中不可用。您需要升级 WebLogic 以使用 JSF 1.2 并重新声明faces-config.xml您的 webapp 符​​合 JSF 1.2 规范。


与具体问题无关,此时需要保存 JSF 视图是很奇怪的。它不会像您想象的那样包含生成的 Jasper 报告(仅仅是因为这不是 JSF 视图......)。但那是另一回事了。顺便说一句,您不会以任何方式将报告写入响应正文。也许那是你真正的问题?

于 2012-04-29T05:51:13.500 回答