Jsf primefaces数据表工作不正常

Jsf primefaces数据表工作不正常,jsf,primefaces,Jsf,Primefaces,下面是primefaces数据表的XHTML代码 <h:panelGroup id="mode"> <p:panelGrid columns="2"> <p:panelGrid columns="2"> <p:outputLabel style="font-weight: bold;"

下面是primefaces数据表的XHTML代码

<h:panelGroup id="mode">
                    <p:panelGrid columns="2">
                        <p:panelGrid columns="2">
                            <p:outputLabel style="font-weight: bold;"
                                value="Mode Of Payments" />
                            <p:selectOneRadio value="#{invoiceBean.modeOfPayment}"
                                layout="pageDirection">
                                <f:ajax render="mode" />
                                <f:selectItem itemLabel="Cash" itemValue="Cash" />
                                <f:selectItem itemLabel="Cheque" itemValue="Cheque" />
                            </p:selectOneRadio>
                            <p:outputLabel value="Enter Bank Name :" />
                            <p:inputText value="#{invoiceBean.bankName}"
                                disabled="#{invoiceBean.modeOfPayment == 'Cash'}" />
                            <p:outputLabel value="Enter Cheque Number :" />
                            <p:inputText value="#{invoiceBean.chequeNumber}"
                                disabled="#{invoiceBean.modeOfPayment == 'Cash'}" />
                            <p:outputLabel value="Enter Amount :" />
                            <p:inputText value="#{invoiceBean.chequeAmount}" />
                        </p:panelGrid>
                        <p:panelGrid columns="1">
                            <p:dataTable id="transactionTable"
                                value="#{invoiceBean.transactions}" var="transaction">
                                <p:column headerText="Mode Of Payment">
                                    <p:outputLabel value="#{transaction.modeOfPayment}" />
                                </p:column>
                                <p:column headerText="Bank Name">
                                    <p:outputLabel value="#{transaction.bankName}" />
                                </p:column>
                                <p:column headerText="Amount">
                                    <p:outputLabel value="#{transaction.chequeAmount}" />
                                </p:column>
                                <p:column headerText="Balance">
                                    <p:outputLabel value="#{transaction.balance}" />
                                </p:column>
                                <p:summaryRow>
                                    <p:column colspan="3">
                                        <p:outputLabel value="Remaining Balance" />
                                    </p:column>
                                    <p:column>
                                        <p:outputLabel value="#{transaction.balance}" />
                                    </p:column>
                                </p:summaryRow>
                            </p:dataTable>
                        </p:panelGrid>
                    </p:panelGrid>
                </h:panelGroup>
                <p:commandButton value="Save New Invoice"
                    action="#{invoiceBean.addRow}"
                    update=":form:invoiceTable :form:transactionTable growl"
                    process="@form invoiceTable" onclick="PF('addInvoice').hide();">
                    <f:ajax render=":form:transactionTable" />
                    <f:ajax render=":form:invoiceTable" />
                </p:commandButton>
当我在HTML表格中添加新记录时,单击“保存新发票”时,它将显示在transactionTable中。
它第一次正常工作,但当我单击单选按钮并选择支票选项“不显示新数据”和“替换旧数据”时。

您不应该在getter/setters中执行业务逻辑

普通的getter/setter对看起来与IDE自动生成的平均值完全相同:

public List<Transaction> getTransactions() {
    return transactions;
}

public void setTransactions(List<Transaction> transactions) {
    this.transactions = transactions;
} 
为了在编辑后保存/更新数据,只需使用actionlistener方法

另见:
谢谢,但我有一个错误,在托管bean Invoicean上执行资源注入时出错。现在怎么解决呢?显然,交易或发票为空,或者get0不存在。只要检查堆栈跟踪的根本原因就可以找到线索,这应该是一个非常基本的非JSF问题。我不能再多说了,因为你没有展示代码的那一部分。但这一部分并不相关。你至少应该确保你不去碰那些能手/二传手。然后解决了当前问题中所述的具体问题。
public List<Transaction> getTransactions() {
    return transactions;
}

public void setTransactions(List<Transaction> transactions) {
    this.transactions = transactions;
} 
@PostConstruct
public void init() {
    transactions = transactionDao.getTransactions(invoices.get(0).getId());
}