gpt4 book ai didi

java - 无法在 primefaces 数据表中显示静态 int 变量

转载 作者:行者123 更新时间:2023-11-29 10:14:26 24 4
gpt4 key购买 nike

我正在使用 primefaces 数据表来显示我的数据这是我的代码:

<p:dataTable id="tab6" var="comp" value="#{excelReport.report6}" rendered="#{excelReport.date != null}">
<f:facet name="header">
<h:outputText value="heading text"/>
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column headerText="Sr No" />
<p:column headerText="Years" />
<p:column headerText="Quarter no." />
<p:column headerText="POL" />
<p:column headerText="LPG" />
<p:column headerText="AVIATION" />
<p:column headerText="LUBES" />
<p:column headerText="OTHERS" />
</p:row>
</p:columnGroup>
<p:column><h:outputText value="#{comp.serialNo}" /> </p:column>
<p:column><h:outputText value="#{comp.quarterRange}" /></p:column>
<p:column><h:outputText value="#{comp.quarterNumber}" /></p:column>
<p:column><h:outputText value="#{comp.pol}" /></p:column>
<p:column><h:outputText value="#{comp.lpg}" /></p:column>
<p:column><h:outputText value="#{comp.aviation}" /></p:column>
<p:column><h:outputText value="#{comp.lubes}" /></p:column>
<p:column><h:outputText value="#{comp.others}" /></p:column>
<p:columnGroup type="footer">
<p:row>
<p:column footerText="Total" colspan="3"/>
<p:column footerText="#{comp.polTotal}"/>
<p:column footerText="#{comp.lpgTotal}"/>
<p:column footerText="#{comp.aviationTotal}"/>
<p:column footerText="#{comp.lubesTotal}"/>
<p:column footerText="#{comp.othersTotal}"/>
</p:row>
</p:columnGroup>
</p:dataTable>

一切正常,只是我的页脚行中没有任何数据。我试图在我的 footerText 中显示 int 类型的静态变量。

这里是 bean 类:

package dao;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class Excel_Target_Compliance implements Serializable {

public Excel_Target_Compliance() {
}
private String quarterRange;
private String quarterNumber;
private int pol;
private int lpg;
private int aviation;
private int lubes;
private int others;
private int serialNo;
static int polTotal;
static int lpgTotal;
static int aviationTotal;
static int lubesTotal;
static int othersTotal;

public static int getPolTotal() {
return polTotal;
}

public static int getLpgTotal() {
return lpgTotal;
}

public static int getAviationTotal() {
return aviationTotal;
}

public static int getLubesTotal() {
return lubesTotal;
}

public static int getOthersTotal() {
return othersTotal;
}

public int getSerialNo() {
return serialNo;
}

public void setSerialNo(int serialNo) {
this.serialNo = serialNo;
}

public String getQuarterRange() {
return quarterRange;
}

public void setQuarterRange(String quarterRange) {
this.quarterRange = quarterRange;
}

public String getQuarterNumber() {
return quarterNumber;
}

public void setQuarterNumber(String quarterNumber) {
this.quarterNumber = quarterNumber;
}

public int getPol() {
return pol;
}

public void setPol(int pol) {
polTotal = polTotal + pol;
this.pol = pol;
}

public int getLpg() {
return lpg;
}

public void setLpg(int lpg) {
lpgTotal = lpgTotal + lpg;
this.lpg = lpg;
}

public int getAviation() {
return aviation;
}

public void setAviation(int aviation) {
aviationTotal = aviationTotal + aviation;
this.aviation = aviation;
}

public int getLubes() {
return lubes;
}

public void setLubes(int lubes) {
lubesTotal = lubesTotal + lubes;
this.lubes = lubes;
}

public int getOthers() {
return others;
}

public void setOthers(int others) {
othersTotal = othersTotal + others;
this.others = others;
}
}

最佳答案

  public static int getPolTotal() {
return polTotal;
}

您不能将 getter 设为静态。Primefaces View 无法识别这一点。

getter 更改为:

 public int getPolTotal() {
return polTotal;
}

您仍然可以将 variable 作为 static。 (private static int polTotal;)

关于java - 无法在 primefaces 数据表中显示静态 int 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21904544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com