如何使用旧数据输入禁用inputText?

时间:2014-08-21 10:48:19

标签: jsf primefaces

点击"添加发票"按钮然后打开对话框。 填写一些数据并将其保存在数据库表中。 当我点击"添加发票"按钮第二次primefaces inputText值是旧数据和inputText当时禁用。 但是以下代码无法正常工作。 始终输入文本空白,禁用true ... 请帮我。感谢

<p:dataTable id="invoiceTable" var="invoiceProductsServicesDetail"
    value="#{invoiceBean.invoiceProductsServicesDetails}" border="1"
    editable="true">
    <p:column headerText="Sr. No.">
        <p:outputLabel
            value="#{invoiceProductsServicesDetail.serialNumber}" />
        </p:column>
        <p:column headerText="HSN Code">
            <p:outputLabel value="#{invoiceProductsServicesDetail.hsnCode}" />
        </p:column>
        <p:column headerText="Quantity">
            <p:outputLabel value="#{invoiceProductsServicesDetail.quantity}" />
        </p:column>
        <p:column headerText="Rate">
            <p:outputLabel value="#{invoiceProductsServicesDetail.rate}" />
        </p:column>
        <p:column headerText="Percentage Discount">
            <p:outputLabel
                value="#{invoiceProductsServicesDetail.percentDiscount}" />
        </p:column>
        <f:facet name="footer">
            <p:commandButton value="Add Invoice" type="button"
                onclick="PF('addInvoice').show();" />
        </f:facet>
 </p:dataTable>

单击&#34;添加发票&#34;打开Dialoag框后面。按钮。它得到了输入。

<p:dialog id="invoiceDialog" header="Add Invoice"
    widgetVar="addInvoice" minHeight="40" showEffect="explode"
    hideEffect="fold">
    <table border="1" id="dialogTable">
        <tr>
            <td><p:outputLabel value="HSN Code" /></td>
            <td><p:outputLabel value="Quantity" /></td>
            <td><p:outputLabel value="Rate" /></td>
            <td><p:outputLabel value="Percentage Discount" /></td>
        </tr>
        <tr>
            <td><p:inputText value="#{invoiceBean.hsnCode}" size="6"
                disabled="#{invoiceBean.hsnCode != null}" /></td>
            <td><p:inputText id="quaintity"
                value="#{invoiceBean.quantity}" size="3" styleClass="Alingment"
                required="true" label="Quantity"
                requiredMessage="Quantity Require Entry" autocomplete="off"
                disabled="#{invoiceBean.quantity != 0}" /></td>
            <td><p:inputText id="rate" value="#{invoiceBean.rate}"
                styleClass="Alingment" required="true" label="Rate"
                requiredMessage="Rate Require Entry" autocomplete="off"
                disabled="#{invoiceBean.rate != 0}" /></td>
            <td><p:inputText value="#{invoiceBean.percentDiscount}"
                size="2" styleClass="Alingment" autocomplete="off"
                disabled="#{invoiceBean.percentDiscount != 0}" /></td>
            </tr>
    </table>
    <p:commandButton value="Save New Invoice"
        action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
        process="@form invoiceTable" onclick="PF('addInvoice').hide();">
        <p:confirm header="Confirmation" message="Are You Sure ?"
                    icon="ui-icon-alert" />
        <f:ajax render=":form:invoiceTable" />
    </p:commandButton>
</p:dialog>

管理Bean:invoiceBean 这里,我使用以下方法将数据存储在特定对象中。

public void addRow() {
    int lastBalance, currentBalance, storeBalance;
    transaction = new Transaction();
    invoiceProductsServicesDetail = new InvoiceProductsServicesDetail();
    invoiceDao = new InvoiceDao();
    transactionDao = new TransactionDao();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    DataTable dataTable = (DataTable) facesContext.getViewRoot()
            .findComponent("form:invoiceTable");
    UIComponent uiTable = ComponentUtils.findParentForm(facesContext,
            dataTable);
    final AjaxBehavior behavior = new AjaxBehavior();
    try {
        if (descriptionOfGoodsOrService != ""
                && descriptionOfGoodsOrService != null && rate != 0
                && quantity != 0) {
            amount = (rate * quantity);
            this.grossTotal = amount = (amount - (amount * (percentDiscount / 100)));
            this.netTotal = ((amount) + (amount * (Constants.VAT / 100)) + (amount * (Constants.SERVICE_TAX / 100)));

            if (chequeAmount <= amount) {
                invoiceProductsServicesDetails = invoiceDao.getInvoiceProductsServicesDetailData(invoices.get(
                        0).getId());

                transactions = transactionDao.getTransactions(invoices.get(
                        0).getId());
                invoiceProductsServicesDetail.setSerialNumber(dataTable
                        .getRowCount() + 1);
                invoiceProductsServicesDetail.setHsnCode(hsnCode);
                invoiceProductsServicesDetail
                        .setPercentDiscount(percentDiscount);
                invoiceProductsServicesDetail.setQuantity(quantity);
                invoiceProductsServicesDetail.setRate(rate);
                invoiceProductsServicesDetail.setInvoiceId(invoices.get(0)
                        .getId());

                invoiceProductsServicesDetails
                        .add(invoiceProductsServicesDetail);

                if (transactions.size() != 0) {
                    setTransactions(transactions);
                    lastBalance = transactions.get(transactions.size() - 1)
                            .getBalance();
                } else {
                    lastBalance = 0;
                }
                currentBalance = amount - chequeAmount;
                storeBalance = lastBalance + currentBalance;

                transaction.setModeOfPayment(modeOfPayment);
                if (modeOfPayment.equals("Cheque")) {
                    transaction.setBankName(bankName);
                    transaction.setChequeNumber(chequeNumber);
                    transaction.setBalance(storeBalance);
                } else {

                    transaction.setBalance(storeBalance);

                }
                transaction.setChequeAmount(chequeAmount);
                transaction.setReceiptNumber(String.valueOf(new Date()
                        .getTime()));
                transactionDao.setTransaction(transaction, invoices.get(0).getId());
                this.transactions = transactionDao.getTransactions(invoices.get(0).getId());
                invoiceDao.insertInvoiceProductsServicesDetail(invoiceProductsServicesDetail);
                RowEditEvent rowEditEvent = new RowEditEvent(uiTable,behavior, invoiceProductsServicesDetail);
                rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
                dataTable.broadcast(rowEditEvent);
            } else {

                FacesMessage message = new FacesMessage(
                        FacesMessage.SEVERITY_INFO, "System Error",
                        "Your Enter Amout Is Must Less Then Total Amount");
                facesContext.addMessage(null, message);
            }

        }
    } catch (AbortProcessingException e) {
        e.printStackTrace();
    } finally {
        invoiceProductsServicesDetail = null;
    }
}

1 个答案:

答案 0 :(得分:1)

在打开对话框之前,你没有清除对话框。

更改

<p:commandButton value="Add Invoice" type="button"
    onclick="PF('addInvoice').show();" />

<p:commandButton value="Add Invoice" type="button"
    action="#{invoiceBean.createInvoice}" update="invoiceDialog"
    oncomplete="PF('addInvoice').show();" />

使用

public void createInvoice() {
    hsnCode = null;
    quantity = null;
    rate = null;
    percentDiscount = null;
}

那就是说,你的模型的设计被打破了。您可以直接在辅助bean中展平并重复模型的属性,而不是直接使用模型。通过删除 hsnCodequantityratepercentDiscount属性进行修复,然后添加:

private InvoiceProductsServicesDetail invoiceProductsServicesDetail;

public void createInvoice() {
    invoiceProductsServicesDetail = new InvoiceProductsServicesDetail();
}

使用

<p:inputText value="#{invoiceBean.invoiceProductsServicesDetail.hsnCode}" ... />
<p:inputText value="#{invoiceBean.invoiceProductsServicesDetail.quantity}" ... />
...

另见: