在下面的代码中,Check Amount小于(quautity * rate),然后显示警告消息。 XHTML代码:
<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:inputText id="description"
value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45"
required="true" label="Description"
requiredMessage="Description Require Entry"
disabled="#{invoiceBean.descriptionOfGoodsOrService != null}" /></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>
<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="Total is :" />
<p:inputText value="#{invoiceBean.chequeAmount}" />
</p:panelGrid>
<p:panelGrid columns="1">
<p:dataTable 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 growl"
process="@form invoiceTable" onclick="PF('addInvoice').hide();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
<p:growl id="growl" showDetail="true" sticky="true" />
</p:dialog>
遵循托管bean代码,它用于存储与事务相关的数据:
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 {
amount = (rate * quantity);
if(chequeAmount <= amount){
transactions = transactionDao.getTransactions(invoices.get(0).getId());
if (transactions.size() != 0) {
setTransactions(transactions);
lastBalance = transactions.get(transactions.size() - 1).getBalance();
} else {
lastBalance = 0;
}
currentBalance = chequeAmount - amount;
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());
RowEditEvent rowEditEvent = new RowEditEvent(uiTable, behavior, invoiceProductsServicesDetail);
rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
dataTable.broadcast(rowEditEvent);
}else{
//Diplay Alert Message that "Producats/Services total amount Must greater than your cheque amount"
}
}
} catch (AbortProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
然后在交易数据存储之后不存在。
答案 0 :(得分:0)
放入其他部分
FacesMessage facesMessage = new FacesMessage();
facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
facesMessage.setDetail("Producats/Services total amount Must greater than your cheque amount");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
return null;