我有一个简单的Primefaces Datatable和SummaryRow。此SummaryRow的值在ManagedBean中计算,并在简单的BigDecimal变量中可用。 DataTable按字符串字段排序。
不知何故,DataTable在每行显示的是summaryRow,而不是在最后一行。
我已经搜索了这个,但没有找到任何相关信息。
我使用Primefaces 5.3和JSF 2.2。
表格: (https://drive.google.com/file/d/0Bw9aJmydXWmvdU8yTUkyYnp0Ums/view)
XHTML:
<p:dataTable
id="rgmStoricoContrattiSogettoCapogruppoDataTable"
value="#{storicoSoggettoProdottoBean.sogegettoProdottoList}"
var="soggetto"
rendered="#{storicoSoggettoProdottoBean.isNdgMemberOfGroup()}"
styleClass="common_datagrid"
emptyMessage="Nessun valore presente"
sortBy="#{soggetto.denominazione}" >
<p:column headerText="Soggetto">
<p:commandLink
value="#{soggetto.denominazione} #{soggetto.ndg} - #{soggetto.ndgCapogruppo}"
actionListener="#{storicoSoggettoProdottoBean.redirectSoggetoProdotto(request.contextPath, soggetto)}"
immediate="true"
process="@this"
style="font-size: 11px !important;" />
</p:column>
<p:column headerText="Rating And./Cerved" width="67" style="text-align: center">
<h:outputText value="#{soggetto.rating} / #{soggetto.ratingCerved}" />
</p:column>
<p:column headerText="Perfez. storico" width="60" style="text-align: right">
<h:outputText value="#{soggetto.perfezionato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Accord." width="60" style="text-align: right">
<h:outputText value="#{soggetto.accordato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Utilizz." width="60" style="text-align: right">
<h:outputText value="#{soggetto.utilizzato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Sconfino" width="60" style="text-align: right">
<h:outputText value="#{soggetto.sconfino}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="In proposta" width="60" style="text-align: right">
<h:outputText value="#{soggetto.inProposta}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Garanzie bancarie" width="60" style="text-align: right">
<h:outputText value="#{soggetto.garanzieBancarie}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Rischio indiretto vs gruppo" width="87" style="text-align: center;">
<h:outputText rendered="#{soggetto.rischioIndirettoVsGruppo == true}" value="SÍ" style="color: green; font-weight: bold;" />
</p:column>
<p:column headerText="Rischio indiretto vs terzi" width="60" style="text-align: right">
<h:outputText value="#{soggetto.rischioIndirettoVsTerzi}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column headerText="Rischio pond." width="60" style="text-align: right">
<h:outputText value="#{soggetto.rischioPonderato}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column width="25">
<p:commandButton
action="#{storicoSoggettoProdottoBean.redirectToStoricoPlafond(request.contextPath, soggetto)}"
immediate="true"
process="@this"
icon="fa fa-file-text-o"
styleClass="imageButton"
style="height: 12px;" />
</p:column>
<p:summaryRow>
<p:column styleClass="totaleRowColor" style="text-align: right;">
<h:outputText value="Totale:" style="font-weight: bold; text-transform: uppercase;" />
</p:column>
<p:column styleClass="totaleRowColor" width="67" />
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.perfezionatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.accordatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.utilizzatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.sconfinoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.inPropostaSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.garanzieBancarieSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" width="87" />
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.rischioIndirettoVsTerziSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
<h:outputText value="#{storicoSoggettoProdottoBean.rischioPonderatoSoggettoSum}">
<f:convertNumber type="currency" currencySymbol="€"/>
</h:outputText>
</p:column>
<p:column styleClass="totaleRowColor" width="25" />
</p:summaryRow>
答案 0 :(得分:2)
如this question所述,您必须在p:dataTable标记上提供sortBy属性才能使摘要行正常工作(就像您在代码段中所做的那样)。 Primefaces使用sortBy标记中的表达式对表条目进行分组,然后为每个组提供摘要行。
为了只获得一个小组,我尝试了这个:
<p:dataTable sortBy="#{1}" ...>
对我来说工作正常,我现在只得到一个总结。
答案 1 :(得分:1)
不确定预期结果是否需要列上的colspan属性??
如果您不知道,请检查Primefaces的展示样本:http://www.primefaces.org/showcase/ui/data/datatable/summaryRow.xhtml
答案 2 :(得分:0)
摘要行使用sortBy表达式,因此,如果您使用sortBy即唯一ID,则Primefaces总是会为表中的每一行提供摘要行。使用类似于Ginkobonsai的sortBy常量建议sortBy =“#{1}”是个好主意,您也可以在POJO中使用常量字段。
答案 3 :(得分:0)
您可以使用所有行共享的某些数据的排序值。
例如,如果您使用的是var soggetto
然后您可以在该类上拥有一个在所有对象之间均相等的字段。
例如soggetto.dummysortby
在类getDummySortBy中返回1。