Primefaces jasper报告并导航到其他页面

时间:2016-01-08 10:08:36

标签: forms jsf-2 primefaces navigation jasper-reports

使用primefaces 5.3,在表单提交按钮上我需要使用表单值更新数据库并在新选项卡中打开jasper报表,而源页面应该导航到其他页面。目前我有两个单独的按钮正在完成这项工作,但点击第二个按钮是多余的,我想避免。 以下是测试代码 用于更新数据库的Backing bean方法

public String createVoucher(){  
    initAllVariables();

    try{
            tempSessionVars();
            this.item=fillVoucher();
            this.create();
            List<Voucherdetails> cashvdlist = new ArrayList<>(this.item.getVoucherdetailsCollection());
            printflag=true;
            iterateSelection();
            profilelist=new ArrayList();
            profilemap.clear();
            testlist=new ArrayList();
            testmap.clear(); 

    }catch(Exception e){
        e.printStackTrace();
    }
    return "/pfpages/aaPatient3/wizardpages/PatientCreate.xhtml"; //After execution return to this page
}

处理jasper报告的方法

public void printFirstCashSlipAfterRegistration(){
    initAllVariables();
    List<Voucherdetails> cashvdlist = new ArrayList<>(this.item.getVoucherdetailsCollection());
    String testprofilecashsliplist=AReportPrint.convertVoucherdetailsToString(cashvdlist);
    try{
        AReportPrint.printCashSlip(testprofilecashsliplist, item);
    }catch(NullPointerException npe){
        System.err.println("Null pointer exception at createVoucher during printCashSlip" + npe.getMessage());
    }
}

目前在我的xhtml页面中,我创建了两个表单,每个表单都有一个单独的命令按钮,用于处理上述两种方法

<h:panelGroup id="selectedtestpanel3">
<h:form id="SelectedTests3" >     
    <p:selectOneMenu id="CompanyPanelsList" value="#{aTestRegController.selectedpanel}" required="true" converter="#{pfpagesConverter}">
        <p:ajax event="change"  listener="#{aTestRegController.onCompanyPanelChange}"
                update="patientRegWizard:displayprices"
                />
        <f:selectItems value="#{aTestRegController.panellist}" var="panel" itemValue="#{panel}"/>

    </p:selectOneMenu>
    <p:dataTable id="selectedTestDataTable3" value="#{aTestRegController.testprofilelist}" var="seltestprofile" 
                 rowKey="#{aTestRegController.selectedToString(seltestprofile)}" tableStyle="width:auto" resizableColumns="true"
                 selectionMode="single" selection="#{aTestRegController.selected}" style="vertical-align:top;"
                 >
        <p:ajax event="rowSelect" listener="#{aTestRegController.testprofilePull(aTestRegController.selected)}" 
                update="patientRegWizard:SelectedTests3, patientRegWizard:displayprices"/>

        <p:column headerText="Test/Profile Name" width="10">
            <h:outputText value="#{aTestRegController.selectedTestProfileName(seltestprofile)}"/>
        </p:column>
        <p:column headerText="Price" width="10">
            <h:outputText value="#{aTestRegController.selectedTestProfilePrice(seltestprofile)}"/>
        </p:column>
        <p:column headerText="Container" width="10">
            <h:outputText value="#{aTestRegController.selectedTestProfileContainer(seltestprofile)}"/>
        </p:column>
    </p:dataTable>

    <p:commandButton id="saveReg2" icon="ui-icon-plus"   value="Save Test Registration01" 
        action="#{aTestRegController.createVoucher()}" 
        disabled="#{empty aTestRegController.testprofilelist}"                                       
        update="patientRegWizard:printform growl" process="@form"
    />

</h:form>                    

<h:panelGroup>
<h:form id="printform" >
    <p:commandButton id="printSlip" value="Print Registration Slip" 
        actionListener="#{aTestRegController.printFirstCashSlipAfterRegistration()}" 
        process="@form"
        ajax="false" onclick="this.form.target='_blank'"
    />
</h:form>

可以合并这两个按钮上的操作吗?

编辑: 我尝试了来自Call multiple bean method in primefaces simultaneously的action和actionListener的BalusC解决方案 但由于调用Jasper Report方法需要Ajax =“false”,因此两个方法都会触发,但是actionListener会触发两次导致数据库中的异常,并且操作不会导航到该操作的结果。

<p:commandButton id="saveReg2" icon="ui-icon-plus"   value="Save Test Registration01" 
                        actionListener="#{aTestRegController.createVoucher()}" 
                        action="#{aTestRegController.printFirstCashSlipAfterRegistration()}" 
                        disabled="#{empty aTestRegController.testprofilelist}"                                       
                        update="patientRegWizard:printform growl" 
                        ajax="false" onclick="this.form.target='_blank'"
                    />

0 个答案:

没有答案