这里,XHTML代码,其中包含2primeface数据表。 我想通过#{invoice.id}值将对话框inputText值传递给Managed Bean的addRow()。 但是所有inputText的值都变为NULL。 新行数据将在invoiceTable中更新并显示新的entery。
<p:panelGrid columns="3">
<p:outputLabel value="Enter Invoice Number :" />
<p:inputText id="inputInvoiceNumber"
value="#{invoiceBean.invoiceNumber}" />
<p:commandButton value="Search" type="submit">
<f:ajax execute="inputInvoiceNumber" render="outputInvoiceNumber" />
</p:commandButton>
</p:panelGrid>
<br />
<p:dataTable id="outputInvoiceNumber"
value="#{invoiceBean.invoices}" var="invoice">
<p:column headerText="Invoice Id ">
<p:outputLabel value="#{invoice.id}" />
</p:column>
<p:column headerText="Email">
<p:outputLabel value="#{invoice.email}" />
</p:column>
<p:column headerText="Invoice Number ">
<p:outputLabel value="#{invoice.invoiceNumber}" />
</p:column>
<p:column headerText="Date">
<p:outputLabel value="#{invoice.date}" />
</p:column>
<p:column headerText="Delivery Note ">
<p:outputLabel value="#{invoice.deliveryNote}" />
</p:column>
<p:column headerText="Supplier Reference">
<p:outputLabel value="#{invoice.supplierReference}" />
</p:column>
<p:column headerText="Other Reference">
<p:outputLabel value="#{invoice.otherReference}" />
</p:column>
<p:column headerText="Buyer Name">
<p:outputLabel value="#{invoice.buyerName}" />
</p:column>
<p:column headerText="Buyer Address">
<p:outputLabel value="#{invoice.buyerAddress}" />
</p:column>
<p:column headerText="Dispatch Document Date">
<p:outputLabel value="#{invoice.dispatchDocumentDate}" />
</p:column>
<p:column headerText="Dispatch Through">
<p:outputLabel value="#{invoice.dispatchThrough}" />
</p:column>
<p:column headerText="Destination">
<p:outputLabel value="#{invoice.destination}" />
</p:column>
<p:column headerText="Terms Of Delivery">
<p:outputLabel value="#{invoice.termsOfdelivery}" />
</p:column>
<p:column headerText="Net Total">
<p:outputLabel value="#{invoice.netTotal}" />
</p:column>
</p:dataTable>
<br />
<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="Description of Goods">
<p:outputLabel
value="#{invoiceProductsServicesDetail.descriptionOfGoodsOrService}" />
</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>
<p:column headerText="Amount">
<p:outputLabel
value="#{(invoiceProductsServicesDetail.rate) * (invoiceProductsServicesDetail.percentDiscount) }" />
</p:column>
<p:summaryRow>
<p:column colspan="5" style="text-align:right">
<p:outputLabel value="Total" />
</p:column>
<p:column>
<p:outputLabel value="#{invoiceBean.netTotal}" />
</p:column>
</p:summaryRow>
<f:facet name="footer">
<p:commandButton value="Add Invoice" type="button"
onclick="PF('addInvoice').show();" />
</f:facet>
</p:dataTable>
<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="Description Of Goods Or Services" /></td>
<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:inputTextarea id="description"
value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45"
required="true" label="Description"
requiredMessage="Description Require Entry" /></td>
<td><p:inputText value="#{invoiceBean.hsnCode}" size="6" /></td>
<td><p:inputText id="quaintity"
value="#{invoiceBean.quantity}" size="3" styleClass="Alingment"
required="true" label="Quantity"
requiredMessage="Quantity Require Entry" autocomplete="off" /></td>
<td><p:inputText id="rate" value="#{invoiceBean.rate}"
styleClass="Alingment" required="true" label="Rate"
requiredMessage="Rate Require Entry" autocomplete="off" /></td>
<td><p:inputText value="#{invoiceBean.percentDiscount}"
size="2" styleClass="Alingment" autocomplete="off" /></td>
</tr>
</table>
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="@this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
<p:growl id="growl" showDetail="true" sticky="true" />
</p:dialog>
<br />
<p:commandButton value="Create Pdf"
action="#{createPdf.createPdfFile}" ajax="false">
<f:setPropertyActionListener value="#{invoiceBean.invoiceNumber}"
target="#{createPdf.invoiceNumber}" />
</p:commandButton>
</h:panelGroup>
这里,Managed Bean的addRow()方法用于在invoiceTable中添加新行,并使用对话框输入的新值:invoiceBean
public void addRow() {
invoiceProductsServicesDetail = new InvoiceProductsServicesDetail();
invoiceDao = new InvoiceDao();
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) {
invoiceProductsServicesDetail.setSerialNumber(dataTable
.getRowCount() + 1);
invoiceProductsServicesDetail
.setDescriptionOfGoodsOrService(descriptionOfGoodsOrService);
invoiceProductsServicesDetail.setHsnCode(hsnCode);
invoiceProductsServicesDetail
.setPercentDiscount(percentDiscount);
invoiceProductsServicesDetail.setQuantity(quantity);
invoiceProductsServicesDetail.setRate(rate);
invoiceProductsServicesDetail.setInvoiceId(id);
invoiceProductsServicesDetails
.add(invoiceProductsServicesDetail);
amount = (rate * quantity);
this.grossTotal = amount = (amount - (amount * (percentDiscount / 100)));
this.netTotal = ((amount) + (amount * (Constants.VAT / 100)) + (amount * (Constants.SERVICE_TAX / 100)));
System.out.println(grossTotal);
System.out.println(netTotal);
invoiceDao
.insertInvoiceProductsServicesDetail(invoiceProductsServicesDetail);
RowEditEvent rowEditEvent = new RowEditEvent(uiTable, behavior,
invoiceProductsServicesDetail);
rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
dataTable.broadcast(rowEditEvent);
}
} catch (AbortProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
您的对话框提交按钮
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="@this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
仅使用您在对话框中输入的所有值来处理自身和invoiceTable
而不是invoiceDialog
。尝试将其更改为
process="@form invoiceTable"
处理整个对话框。此外,建议以自己的形式包含一个对话框,以便能够处理表单而无需处理与对话框无关的所有周围输入元素。