1

问候来自南美洲。我正在生成一个报告(使用 jasper 报告),所以当这个过程发生时,我想阻止显示适当消息的页面。该报告使用以下代码行完美地触发了该操作:

<p:commandButton id="pago" actionListener="#{transaccionBncController.reporteGeneral}" value="Reporte General " ajax="false"/> 

注意:必须使用 ajax="false" 属性,否则一切都会变糟,并且无法生成报告!

现在,当我尝试添加 Primefaces blockUI 组件以阻止页面并显示适当的消息(生成报告时)时,我正在使用以下代码:

<p:blockUI block="panelGrid" trigger="pago">
 Generando Reporte...<br />  
 <h:graphicImage library="images" name="ajaxloading.gif"/> 
</p:blockUI>

blockUI 组件运行良好,但报告不再起作用。我已经尝试了一切,关于 ajax="false" 属性和阻止页面的问题总是相同的。

以下是我正在研究的整个来源:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/template.xhtml">

    <ui:define name="content" >
        <fieldset id="fieldsetgenerico" >
            <legend> Reporte General </legend>
            <h:form id="formreporte">
                <p:growl autoUpdate="true" life="3000"  id="growl" />  
                <h:panelGrid columns="3" id="panelGrid" >

                    <h:outputLabel value="Fecha inicial: " for="fechaInicial" /> 
                    <p:calendar id="fechaInicial" value="#   {transaccionBncController.fechaInicial}" pattern="dd/MM/yyyy"  locale="es" required="true" requiredMessage="Fecha Inicial Requerida" navigator="true" effect="fadeIn" effectDuration="100"/>

                    <h:outputLabel value="" /> 

                    <h:outputLabel value="Fecha Final: " for="fechaFinal"/>
                    <p:calendar id="fechaFinal" value="# {transaccionBncController.fechaFinal}" pattern="dd/MM/yyyy" locale="es" required="true" requiredMessage="Fecha Final Requerida" navigator="true" effect="fadeIn" effectDuration="300"/>

                    <p:tooltip for="fechaFinal" value="Campo Requerido. No puede ser anterior a la Fecha Inicial" showEffect="clip" hideEffect="clip" />

                    <h:outputLabel value="Estado: " for="estado"  />     
                    <h:selectOneMenu id="estado" value="#{transaccionBncController.estTra}"  >                                       
                        <f:selectItems value="#{estadoTransaccionBncController.itemsAvailableSelectOne}"  />                                    
                    </h:selectOneMenu>
                    <h:outputLabel value="" />

                    <h:outputLabel value="Tipo Transaccion: " for="tipoTransaccion"/>
                    <h:selectOneMenu id="tipoTransaccion" value="#{transaccionBncController.tipTra}"  
                                     valueChangeListener="#{transaccionBncController.defineTipoTransaccion}"  >
                        <f:selectItems value="#{tipoTransaccionBncController.itemsAvailableSelectOne}"/>
                        <f:ajax  execute="@all" render="panelGrid1" immediate="true"></f:ajax>     
                    </h:selectOneMenu>
                    <h:outputLabel value="" />

                    <h:outputLabel value="Entidad Financiera: " for="entidadFinanciera"  />                               
                    <h:selectOneMenu id="entidadFinanciera" value="#{transaccionBncController.cliente}" 
                                     valueChangeListener="#{transaccionBncController.actualizaAgencias}" >  
                        <f:selectItems value="#{clienteBncController.itemsAvailableSelectOne}"/>  
                        <f:ajax  execute="@form" render="panelGrid" ></f:ajax> 
                    </h:selectOneMenu>
                    <h:outputLabel value="" /> 

                    <h:outputLabel value="Agencia: " for="agencia"  />
                    <h:selectOneMenu id="agencia" value="#{transaccionBncController.ag}"  >
                        <f:selectItems value="#{transaccionBncController.itemsAvailableSelectOneAgencia}"/>                 
                    </h:selectOneMenu>
                    <h:outputLabel value="" /> 

                    <h:outputLabel value="Código Financiero: " for="codFinanciero"  />
                    <h:selectOneMenu id="codFinanciero" value="#{transaccionBncController.codigoFinanciero}"   >
                        <f:selectItems value="#{productoBncController.itemsAvailableSelectOneC}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="" />

                </h:panelGrid>           
                <br/>               
                <h:panelGrid columns="2" id="panelGrid1">   
                    <p:commandButton id="pago" icon="ui-icon-check"  actionListener="#{transaccionBncController.reporteGeneral}" value="Reporte General " rendered="#{transaccionBncController.tipTransaccion != 'ANULACION' }" update="growl" style="margin:0" /> 
                    <p:blockUI block="panelGrid" trigger="pago"  >
                        Generando Reporte<br />  
                        <h:graphicImage library="images" name="ajaxloading.gif"/> 
                    </p:blockUI>    
                </h:panelGrid>      
            </h:form>
        </fieldset>
    </ui:define>
</ui:composition>

</html>

我认为这个问题的根本原因是 ajax 交互,因为生成报告(没有 blockui 代码)效果惊人。这是我从中获取报告的源代码:

public void reporteGeneral(ActionEvent actionEvent) throws JRException, IOException, SQLException {


        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@170.25.18.38:1521:xxx", "xxx", "xxx");

        Map<String, Object> parametros = new HashMap<String, Object>();
        parametros.put("fechaInicial", fInicial);
        parametros.put("fechaFinal", fFinal);
        parametros.put("query", query);


        String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reportes/report4.jasper");
        jasperPrint = JasperFillManager.fillReport(reportPath, parametros, conn);


        //jasperPrint=JasperFillManager.fillReport(reportPath, new HashMap(),conn); 


        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
        String fi = sdf.format(fInicial);
        String ff = sdf.format(fFinal);

        String fecha = fi.toString() + "_" + ff.toString();

        httpServletResponse.addHeader("Content-disposition", "attachment; filename=reporte_" + fecha + ".pdf");
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();

        JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);

        FacesContext.getCurrentInstance().responseComplete();
}

十分感谢大家。对不起,如果这个问题是新手,但我认为这是一个很好的学习机会,因为我在互联网上没有找到关于这个话题的东西。再次,非常感谢您的帮助。圣地亚哥

4

0 回答 0