Primefaces分页(lazydatamodel)加载方法

时间:2015-04-13 15:07:19

标签: jsf primefaces load refresh lazydatamodel

我正在处理一个页面问题。

我有两个部分:frmConf和frmData。

第一个有一些我用于搜索目的的参数。

第二个将DataTable定义为lazy和algo我有相应的支持,扩展了LazyDatamodel。

在第2节中提到的DataTable中,我有一个带有commandLink的列,它为DataTable中的选定行创建PDF文档。

我遇到的问题是我第一次加载页面时效果很好:

它从LazyDatamodel调用load(@override)方法,并显示来自DB的查询结果的前10条记录。

然后,当我点击commandLink列时,它会显示相应PDF的“另存为”对话框,我可以继续下载该文件。

但是,由于某些原因,我还不明白,如果我点击另一行的PDF commandLink,它会调用引用的加载方法,重新查询数据库,假设我试图做一些分页,它不会甚至可以生成所需的PDF。

我想要实现的只是为每个分页案例加载页面,而不是为任何不相关的事件加载,例如单击所选行的PDF按钮。

为什么重新加载和重新查询(即使它显示与分页索引相同的结果还没有改变)第一个(正确的)PDF生成后的整个页面内容? 我的猜测是在第一代PDF生成之后发生的事情(它使页面保留了一些“需要重新加载”的状态。

我从页面中留下了标记以及相应的支持bean PDF生成方法。

如果有人可以帮我解决这个问题,我真的很感激。

谢谢!

JSF标记:

    <!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:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<ui:composition template="/templates/cimaTemplate.xhtml">
    <ui:define name="tituloPagina">
        <h:outputText value="Consulta Documentos" />
    </ui:define>

    <ui:define name="tituloFormulario">
        <h:outputText value="Documentos" styleClass="titulo" />
    </ui:define>
    <ui:define name="contenido">

        <style>
.style1 {
    text-align: right;
}
.style3 {
    text-align: left;
}

.style2 {
    text-align: center;
    background: blue;
    color: white;
    font-weight: bold;
}

.colEstadoStyle {
    td:nth-child(1) 
    width: 20px;
}

.imageClass {
    display: block;
    background-image: url('/imagenes/pdf.png') no-repeat 100%;
}
</style>

    <h:form id="frmConf" styleClass="form" >
        <p:growl id="growl" showDetail="true" sticky="true" />
        <p:panel id="datosEmisorPanel">
            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
            <p:panelGrid style="margin: 0 auto;" id="panelG"> 
                <p:row>
                    <p:column>
                        <p:panelGrid>
                        <p:row>
                            <p:column style="text-align: center;" colspan="2">
                                <strong><h:outputLabel styleClass="label" value="Seleccionar Archivo" /></strong>

                                <p:selectManyCheckbox style="text-align: center;"
                                    value="#{cabDocumentoMB.selectedOptionsEmail}">
                                    <f:selectItem itemValue="PDF" itemLabel="PDF" />
                                    <f:selectItem itemValue="XML" itemLabel="XML" />
                                </p:selectManyCheckbox>
                            </p:column>
                        </p:row> <p:row>
                            <p:column colspan="2">
                                <strong><h:outputLabel styleClass="label"
                                        value="E-Mails" /></strong>
                                <br></br>
                                <h:inputTextarea value="#{cabDocumentoMB.correos}"
                                    cols="40" />
                                <br></br>
                            </p:column>
                        </p:row> <p:row>
                            <p:column colspan="2">
                                <strong><h:outputLabel styleClass="style1"
                                        value="Formato: email1@email.com,email2@email.com" /></strong>
                            </p:column>
                        </p:row> <p:row>
                            <p:column rowspan="2">
                                <p:commandButton icon="ui-icon-mail-closed"
                                    value=" Envio normal" id="bto_enviarEmail"
                                    oncomplete="bloquearPagina.hide()"
                                    onstart="bloquearPagina.show()"
                                    action="#{cabDocumentoMB.EnviarCorreos('Normal')}"
                                    update="growl">
                                </p:commandButton>
                                <p:blockUI block="frmConf" widgetVar="bloquearPagina">
                                Enviando correo...<br />
                                    <p:graphicImage value="/imagenes/ajax-loader.gif" />
                                </p:blockUI>

                                <p:blockUI block="frmConf" widgetVar="bloquearReproceso">
                                Reprocesando...<br />
                                    <p:graphicImage value="/imagenes/ajax-loader.gif" />
                                </p:blockUI>

                            </p:column>
                            <p:column rowspan="2">
                                <p:commandButton value=" Envio ZIP" icon="ui-icon-tag"
                                    action="#{cabDocumentoMB.EnviarCorreos('ZIP')}"
                                    oncomplete="bloquearPagina.hide()"
                                    onstart="bloquearPagina.show()" update="growl">
                                </p:commandButton>
                                <br />
                            </p:column>
                        </p:row> </p:panelGrid>
                    </p:column>

                    <p:column colspan="0">
                        <p:panelGrid> <p:row>
                            <p:column colspan="1" styleClass="style1">
                                <strong><h:outputLabel styleClass="label" size="30"
                                        value="Cédula/RUC/Pasaporte" /></strong>
                            </p:column>
                            <p:column colspan="1" styleClass="style3">
                                <h:inputText styleClass="text" style="font-weight: bold;"
                                    value="#{cabDocumentoMB.ruc}" />
                            </p:column>
                        </p:row> <p:row>
                            <p:column colspan="1" styleClass="style1">
                                <strong><h:outputLabel styleClass="label" size="30"
                                        value="Nombres:" /></strong>
                            </p:column>
                            <p:column colspan="1" styleClass="style3">
                                <h:inputText styleClass="text" style="font-weight: bold;"
                                    value="#{cabDocumentoMB.razonSocial}" />
                            </p:column>
                        </p:row> <p:row>
                            <p:column styleClass="style1">
                                <strong><h:outputLabel styleClass="label"
                                        value="Número del Documento:" /></strong>
                            </p:column>
                            <p:column styleClass="style3">
                                <h:inputText value="#{cabDocumentoMB.numDocumento}"
                                    size="30" title="Número del Documento" placeHolder="TBD"/>
                            </p:column>
                        </p:row> <p:row>
                            <p:column styleClass="style1">
                                <strong><h:outputLabel styleClass="label"
                                        value="Tipo de Documento:" /></strong>
                            </p:column>
                            <p:column styleClass="style3">
                                <p:selectOneMenu
                                    value="#{cabDocumentoMB.seleccionTipo}">
                                    <f:selectItems value="#{cabDocumentoMB.tipo}" />
                                </p:selectOneMenu>
                            </p:column>
                        </p:row> <p:row>
                            <p:column styleClass="style1">
                                <strong><h:outputLabel styleClass="label"
                                        value="Estados:" /></strong>
                            </p:column>
                            <p:column styleClass="style3">
                                <p:selectOneMenu
                                    value="#{cabDocumentoMB.seleccionTipoEstado}">
                                    <f:selectItems value="#{cabDocumentoMB.tipoEstados}" />
                                </p:selectOneMenu>
                            </p:column>
                        </p:row> <p:row>
                            <p:column>
                                <strong><h:outputLabel styleClass="label"
                                        value="Fecha Inicial:" /></strong>
                                <br></br>
                                <p:calendar id="txt_inicial"
                                    value="#{cabDocumentoMB.fechaInicio}"
                                    pattern="yyyy-MM-dd" mask="true" mode="popup" showOn="button"
                                    readonlyInput="true">
                                    <f:convertDateTime type="date" dateStyle="short"
                                        pattern="yyyy-MM-dd" />
                                </p:calendar>
                            </p:column>
                            <p:column>
                                <strong><h:outputLabel styleClass="label"
                                        value="Fecha Final:" /></strong>
                                <br></br>
                                <p:calendar id="txt_final"
                                    value="#{cabDocumentoMB.fechaFinal}"
                                    pattern="yyyy-MM-dd" mask="true" mode="popup" showOn="button"
                                    readonlyInput="true">
                                    <f:convertDateTime type="date" dateStyle="short"
                                        pattern="yyyy-MM-dd" />
                                </p:calendar>
                            </p:column>
                        </p:row> <p:row>
                            <p:column style="text-align: center;">
                                <p:commandButton value=" Busqueda " icon="ui-icon-search"
                                    title="Buscar Filtrado"
                                    action="#{cabDocumentoMB.findDocumentos()}"
                                    update=":frmData:listaDocumentos,:frmConf:datosEmisorPanel">
                                </p:commandButton>
                            </p:column>
                            <p:column>
                                <p:commandButton value="Reprocesar documentos "
                                    icon="ui-icon-tag"
                                    action="#{CabDocumentoMB.reprocesarDocumentos()}"

                                    disabled="#{CabDocumentoMB.botonReprocesarActivo}"
                                    update=":frmData:listaDocumentos,:frmConf:datosEmisorPanel">

                                </p:commandButton>
                                <br />
                            </p:column>
                        </p:row> </p:panelGrid>
                    </p:column>
                </p:row> 
            </p:panelGrid>
        </p:panel>
    </h:form>   


    <h:form id="frmData" styleClass="form">
        <p:panel id="datosDetalle22" >
                  <h:panelGroup id="listaDocumentos">
                    <p:dataTable id="lazyDataTable" 
                                 var="documento"
                                 value="#{cabDocumentoMB.allDocumentos}"
                                 paginator="true" rows="10" rowsPerPageTemplate="10,50,100"
                                 selection="#{cabDocumentoMB.seleccionDocu}"  
                                 update=":frmData:listaDocumentos"
                                 lazy="true">
                        <f:facet name="header">  
                            Consulta de Documentos
                        </f:facet>
                        <p:column headerText="Identificación" style="width:10% ; font-size:11px" >
                            <h:outputText value="#{documento.identificacionComprador}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Razón Social" style="width:25% ; font-size:11px">
                            <h:outputText value="#{documento.razonSocialComprador}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Comprobante" style="width:10% ; font-size:11px">
                            <h:outputText value="#{documento.codigoDocumento}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Número" style="width:10% ; font-size:11px">
                            <h:outputText value="#{documento.id.serie}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Importe total" style="width:7% ; text-align:right ; font-size:11px">
                            <h:outputText value="#{documento.importeTotal}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Fecha Emisión" style="width:7% ; text-align:center ; font-size:11px">
                            <h:outputText value="#{documento.fechaEmision}" style="font-size:11px;" />
                        </p:column>
                        <p:column headerText="Ambiente"
                            style="width:10% ; text-align:center ; font-size:11px">
                            <h:outputText value="#{documento.id.ambiente}" style="font-size:11px;" />
                        </p:column>

                        <p:column headerText="Estado" style="width:20% ; font-size:11px"> 
                            <p:row> 
                                <p:column>
                                    <h:outputText value="#{documento.estadoTransaccion}" style="font-size:11px;" />
                                </p:column>

                                <p:column>
                                    <p:commandButton update=":frmData:display" oncomplete="detalleEstadoDiag.show()" icon="ui-icon-search" style="float:right;">
                                         <f:setPropertyActionListener                                           
                                            target="#{cabDocumentoMB.seleccionDocumentos}" 
                                            value="#{documento}"
                                         />
                                    </p:commandButton>
                                </p:column>
                            </p:row>
                        </p:column>

                        <p:column headerText="PDF" style="font-size:11px" >
                            <p:commandLink action="#{cabDocumentoMB.pdf(documento,'')}"
                                    ajax="false"
                                    disabled="#{CabDocumentoMB.desactivaBotonPDF}"
                                    update=":frmData:datosDetalle22">
                                        <p:graphicImage value="/imagenes/pdf.png" ></p:graphicImage>
                                        <f:setPropertyActionListener
                                            target="#{cabDocumentoMB.documentos}"
                                            value="#{documentos}" >
                                        </f:setPropertyActionListener>
                                </p:commandLink>
                        </p:column>

                        <p:column headerText="XML" style="font-size:11px" >
                            <p:commandLink
                                action="#{cabDocumentoMB.xml(documento)}"
                                ajax="false"
                                update=":frmData:datosDetalle22"
                                disabled="#{CabDocumentoMB.desactivaBotonXML}">
                                <p:graphicImage value="/imagenes/xml.png"></p:graphicImage>
                                <f:setPropertyActionListener
                                    target="#{cabDocumentoMB.documentos}"
                                    value="#{documentos}">
                                </f:setPropertyActionListener>
                            </p:commandLink>
                        </p:column>
                        <p:column selectionMode="multiple"/>
                    </p:dataTable>

                    <p:dialog header="Detalle de estado" widgetVar="detalleEstadoDiag" resizable="false" width="400" showEffect="explode" hideEffect="explode" style="font-size:11px" >
                            <h:panelGrid id="display" columns="2" cellpadding="4">                              
                                <div align="left" style="font-size:11px;"><h:outputText value="Descripción: " style="font-weight:bold" /></div>
                                    <h:outputText value="#{cabDocumentoMB.seleccionDocumentos.msjError}" />
                            </h:panelGrid>
                    </p:dialog>
                </h:panelGroup>
              </p:panel>

              <p:panel id="datosExcel" style="align=center">
                    <h:commandLink>
                        <p:graphicImage value="/imagenes/excel.png" />
                        <p:dataExporter type="xls"
                            postProcessor="#{manager.postProcessXLS}" target="myData"
                            fileName="myexcel" />
                    </h:commandLink>
              </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
</html>

支持:(PDF方法) ...

JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(detallesAdiciones);            
String reportPath = pathReports.get(doc.getId().getCodigoDocumento());
JasperPrint jasperPrint = null;
try {
    jasperPrint = JasperFillManager.fillReport(reportPath, obtenerMapaParametrosReportes(obtenerParametrosInfoTriobutaria(doc), obtenerInfoFactura(lstFactDetAdictDocumento,doc)), beanCollectionDataSource);
    } catch (JRException e) {
        e.printStackTrace();
    }           
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename="+name);

ServletOutputStream servletOutputStream = null;
try {
        servletOutputStream = httpServletResponse.getOutputStream();                
    } catch (IOException e) {
        e.printStackTrace();
    } 
try {
    JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
} catch (JRException e) {
        e.printStackTrace();
        }  
FacesContext.getCurrentInstance().responseComplete();

0 个答案:

没有答案
相关问题