excel - 将条件添加到 p:dataExporter 的目标属性中,以便一次导出两个不同选项卡中的两个数据表,以便在 primefaces 中表现出色
问题描述
我有两个单选按钮,并在我的表单中使用了 p:tabView 和两个选项卡。单击第一个单选按钮时,第一个选项卡启用,单击第二个单选按钮时,第二个选项卡启用。在两个选项卡中都有一个数据表。我想一次将数据表导出为两个选项卡的 excel 格式。为此,我使用 p:dataExporter。我很困惑是否可以在目标中添加条件语句,p:dataExporter
因为对于第一个单选按钮,我必须提供第一个选项卡表的 id,而对于第二个单选按钮,我必须提供第二个选项卡表的 id。如何才能做到这一点 ?我的代码是这样的:
<h:form id="form" target="_blank">
<p:blockUI block="form" trigger="cmdView">
<p:graphicImage value="/resources/img/ajax-load.gif" />
</p:blockUI>
<p:panel header="#{text.form}">
<h:panelGrid columns="5">
<h:outputText for="console" value="SearchType" />
<p:selectBooleanCheckbox id="isBrief" value="#{customerMB.brief}">
<p:ajax listener="#{customerMB.unCheckDetail}"
update="isDetail tabview"></p:ajax>
</p:selectBooleanCheckbox>
<h:outputText value="#{text.Brief} " />
<p:selectBooleanCheckbox id="isDetail" value="#{customerMB.detail}">
<p:ajax listener="#{customerMB.unCheckBrief}"
update="isBrief tabview"></p:ajax>
</p:selectBooleanCheckbox>
<h:outputText value="#{text.Detail}" />
</h:panelGrid>
<p:commandButton id="cmdView" icon="fa fa-search-plus"
value="#{text.View}" actionListener="#{customerMB.generateList}"
process="@this" update="@form" />
<p:commandButton id="cmdExcel" value="#{text.Excel}"
disabled="#{empty customerMB.formList}" icon="fa fa-file-excel-o"
ajax="false">
<p:dataExporter type="xls" target="form:tabview:table1"
fileName="form" postProcessor="#{customerMB.postProcessXLS}" />
</p:commandButton>
</p:panel>
<p:tabView id="tabview" activeIndex="#{customerMB.activeTab}">
<p:tab title="#{text.CustReportBrief}" id="tab1"
disabled="#{customerMB.detail}">
<p:dataTable id="table1" var="tblA" scrollable="true"
resizableColumns="true" value="#{customerMB.List1}"
rowIndexVar="rowSn" paginator="true">
<p:column headerText="#{text.SNo}" width="50">
<h:outputText value="#{tblA.sn}" />
</p:column>
<p:column headerText="#{text.MemberName}">
<h:outputText value="#{tblA.customerName}" />
</p:column>
<p:column headerText="#{text.Address}">
<h:outputText value="#{tblA.custAddress}" />
</p:column>
</p:dataTable>
</p:tab>
<p:tab title="#{text.CustReportDetail}" id="tab2"
disabled="#{customerMB.brief}">
<p:dataTable var="tblB" rowIndexVar="rowSn" scrollable="true"
resizableColumns="true" value="#{customerMB.List2}" id="table2">
<p:column headerText="#{text.SNo}" width="50px;">
<h:outputText value="#{tblB.sn}" />
</p:column>
<p:column headerText="#{text.Name}">
<h:outputText value="#{tblB.customerName}" />
</p:column>
<p:column headerText="#{text.Address}">
<h:outputText value="#{tblB.custAddress}" />
</p:column>
<p:column headerText="#{text.Contact}">
<h:outputText value="#{tblB.custContact}" />
</p:column>
<p:column headerText="#{text.Email}">
<h:outputText value="#{tblB.custEmail}" />
</p:column>
</p:dataTable>
</p:tab>
</p:tabView>
</h:form>
解决方案
我以前遇到过这个问题,我用两个未显示的数据解决了这个问题,commandButton
里面有 dataExporter 并用commandButton
.
<p:commandButton id="cmdExcel" value="#{text.Excel}"
disabled="#{empty customerMB.formList}" icon="fa fa-file-excel-o"
onstart="document.getElementById('btn1').click()"
oncomplete="document.getElementById('btn2').click()"/>
<p:commandButton id="btn1" ajax="false" style="display: none;">
<p:dataExporter target="table1" type="xls" fileName="table1"/>
</p:commandButton>
<p:commandButton id="btn2" ajax="false" style="display: none;">
<p:dataExporter target="table2" type="xls" fileName="table2"/>
</p:commandButton>
推荐阅读
- python - Knative kafka 版本和 python 支持
- python - 给定两个字符串数组,对于列表中的每个字符串,确定它在另一个列表中有多少个字谜。如何提高时间效率?
- python - 为什么我不能遍历 get_queryset 中的对象?
- c++ - 如何在 Windows 上将 std::vector 固定/取消固定到实际的、未压缩的硬件内存?
- azure - 自动续订期间是否会克隆 keyvault 标签?
- numpy - 不等式的最小二乘线性规划
- algorithm - 线性代数,几何。点积的值为 0
- swift - Swift GCD:为什么信号处理程序在函数中不起作用
- scala - 使用枢轴旋转单行 Spark 数据框
- python - 如何模拟在类属性中调用的函数?