title: Display Alert Message at run time in jsf
body: <p>In following code Cheque Amount is less then (quautity * rate) then display alert message.
  XHTML code :</p>
  
  <pre><code>&lt;p:dialog id="invoiceDialog" header="Add Invoice"
                  widgetVar="addInvoice" minHeight="40" showEffect="explode"
                  hideEffect="fold"&gt;
                  &lt;table border="1" id="dialogTable"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;p:outputLabel value="Description Of Goods Or Services" /&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;p:outputLabel value="HSN Code" /&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;p:outputLabel value="Quantity" /&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;p:outputLabel value="Rate" /&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;p:outputLabel value="Percentage Discount" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;p:inputText id="description"
                                  value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45"
                                  required="true" label="Description"
                                  requiredMessage="Description Require Entry"
                                  disabled="#{invoiceBean.descriptionOfGoodsOrService != null}" /&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;p:inputText value="#{invoiceBean.hsnCode}" size="6" /&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;p:inputText id="quaintity"
                                  value="#{invoiceBean.quantity}" size="3" styleClass="Alingment"
                                  required="true" label="Quantity"
                                  requiredMessage="Quantity Require Entry" autocomplete="off" /&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;p:inputText id="rate" value="#{invoiceBean.rate}"
                                  styleClass="Alingment" required="true" label="Rate"
                                  requiredMessage="Rate Require Entry" autocomplete="off" /&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;p:inputText value="#{invoiceBean.percentDiscount}"
                                  size="2" styleClass="Alingment" autocomplete="off" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
  
                  &lt;h:panelGroup id="mode"&gt;
                      &lt;p:panelGrid columns="2"&gt;
                          &lt;p:panelGrid columns="2"&gt;
                              &lt;p:outputLabel style="font-weight: bold;"
                                  value="Mode Of Payments" /&gt;
                              &lt;p:selectOneRadio value="#{invoiceBean.modeOfPayment}"
                                  layout="pageDirection"&gt;
                                  &lt;f:ajax render="mode" /&gt;
                                  &lt;f:selectItem itemLabel="Cash" itemValue="Cash" /&gt;
                                  &lt;f:selectItem itemLabel="Cheque" itemValue="Cheque" /&gt;
                              &lt;/p:selectOneRadio&gt;
                              &lt;p:outputLabel value="Enter Bank Name :" /&gt;
                              &lt;p:inputText value="#{invoiceBean.bankName}"
                                  disabled="#{invoiceBean.modeOfPayment == 'Cash'}" /&gt;
                              &lt;p:outputLabel value="Enter Cheque Number :" /&gt;
                              &lt;p:inputText value="#{invoiceBean.chequeNumber}"
                                  disabled="#{invoiceBean.modeOfPayment == 'Cash'}" /&gt;
                              &lt;p:outputLabel value="Total is :" /&gt;
                              &lt;p:inputText value="#{invoiceBean.chequeAmount}" /&gt;
                          &lt;/p:panelGrid&gt;
                          &lt;p:panelGrid columns="1"&gt;
                              &lt;p:dataTable value="#{invoiceBean.transactions}"
                                  var="transaction"&gt;
                                  &lt;p:column headerText="Mode Of Payment"&gt;
                                      &lt;p:outputLabel value="#{transaction.modeOfPayment}" /&gt;
                                  &lt;/p:column&gt;
                                  &lt;p:column headerText="Bank Name"&gt;
                                      &lt;p:outputLabel value="#{transaction.bankName}" /&gt;
                                  &lt;/p:column&gt;
                                  &lt;p:column headerText="Amount"&gt;
                                      &lt;p:outputLabel value="#{transaction.chequeAmount}" /&gt;
                                  &lt;/p:column&gt;
                                  &lt;p:column headerText="Balance"&gt;
                                      &lt;p:outputLabel value="#{transaction.balance}" /&gt;
                                  &lt;/p:column&gt;
                                  &lt;p:summaryRow&gt;
                                      &lt;p:column colspan="3"&gt;
                                          &lt;p:outputLabel value="Remaining Balance" /&gt;
                                      &lt;/p:column&gt;
                                      &lt;p:column&gt;
                                          &lt;p:outputLabel value="#{transaction.balance}" /&gt;
                                      &lt;/p:column&gt;
                                  &lt;/p:summaryRow&gt;
                              &lt;/p:dataTable&gt;
                          &lt;/p:panelGrid&gt;
                      &lt;/p:panelGrid&gt;
                  &lt;/h:panelGroup&gt;
                  &lt;p:commandButton value="Save New Invoice"
                      action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
                      process="@form invoiceTable" onclick="PF('addInvoice').hide();"&gt;
                      &lt;f:ajax render=":form:invoiceTable" /&gt;
                  &lt;/p:commandButton&gt;
                  &lt;p:growl id="growl" showDetail="true" sticky="true" /&gt;
              &lt;/p:dialog&gt;
  </code></pre>
  
  <p>Following managed bean code it is used to store transaction related data :</p>
  
  <pre><code> 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 &lt;= 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();
      } 
  } 
  </code></pre>
  
  <p>Then after transaction data store otherwise not.</p>