Here, XHTML code, Which have 2primeface datatable.
I want to pass dialog box inputText value to addRow() of Managed Bean with #{invoice.id} value.
But value of all inputText is become NULL.
After new row data will update in invoiceTable and display new 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>
Here, Managed Bean addRow() method which use to add new row in invoiceTable with new value of dialog box input : 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();
}
}
Your dialog submit button
<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>
Only processes itself and the invoiceTable and not the invoiceDialog with all the values you enter in the dialog. Try changing it to
process="#form invoiceTable"
to process the whole dialog. Additionally, it is advisable to contain a dialog in an own form to be able to process the form without having to process all surrounding input elements not related to the dialog.
Related
I´m trying to show the progress of several batch processes using a progressbar for each one of them. The problem is that only one progressbar is been sent to server side (the last one). Here is the code...
I made a RequestScoped Named bean for the progress beacause I read that for multiple progressBar it is needed a bean instance for each one of the progressbars, but that do not resolve my problem.
I'm using Primefaces 6.1 with JSF 2.2.
Any ideas? Thanks!
<h:form id="formExecutions">
<p:dataGrid id="jobs" value="#{jobExecutorController.jobExecutions}" var="job" rows="5" paginator="true" emptyMessage="#{MessageResources['text.noRecordsFound']}"
paginatorPosition="bottom" columns="1" layout="grid">
<f:facet name="header">
#{MessageResources['text.batchProcesses']}
</f:facet>
<p:outputPanel layout="block" >
<p:panelGrid cellpadding="5" styleClass="vf-panelGrid">
<p:row style="width:100%">
<p:column>
<p:outputLabel for="executionId" value="#{MessageResources['text.executionId']}:" style="font-weight:bold"/>
</p:column>
<p:column>
<h:outputText id="executionId" value="#{job.executionId}" />
</p:column>
<p:column>
<p:outputLabel for="name" value="#{MessageResources['text.name']}:" style="font-weight:bold"/>
</p:column>
<p:column style="width:10%">
<h:outputText id="name" value="#{job.name}"/>
</p:column>
<p:column style="width:50%" rowspan="2">
<p:progressBar id="progressBar" widgetVar="progressBar" ajax="true" value="#{progressController.progress(job)}" labelTemplate="{value}%" styleClass="animated" style="height: 20px; line-height: 20px;" global="false" interval="3000">
<p:ajax event="complete" listener="#{progressController.onCompleteJob(job)}" update="messageDisplay" process="#this"/>
<p:ajax update="jobInfo"/>
</p:progressBar>
</p:column>
<p:column style="width:4%" />
<p:column rowspan="2" style="text-align:right">
<p:commandButton id="restart" onclick="PF('confirmRestartJob').show()" styleClass="coloured-icons-batch restart-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="restart" value="#{MessageResources['text.restartJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="stop" onclick="PF('confirmStopJob').show()" styleClass="coloured-icons-batch stop-image-icon blink"
disabled="#{not job.enableStop}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="stop" value="#{MessageResources['text.stopJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="abandon" onclick="PF('confirmAbandonJob').show()" styleClass="coloured-icons-batch abandon-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="abandon" value="#{MessageResources['text.abandonJobExecution']}" position="top"></p:tooltip>
</p:column>
</p:row>
</p:panelGrid>
<h:panelGroup id="jobInfo" >
<p:panelGrid columns="4" cellpadding="5" styleClass="vf-panelGrid">
<p:outputLabel for="creationDate" value="#{MessageResources['text.creationDate']}:" style="font-weight:bold"/>
<h:outputText id="creationDate" value="#{job.formattedDate(job.createdDate)}" />
<p:outputLabel for="startDate" value="#{MessageResources['text.dateStartProcess']}:" style="font-weight:bold"/>
<h:outputText id="startDate" value="#{job.formattedDate(job.startedDate)}" />
<p:outputLabel for="lastUpdate" value="#{MessageResources['text.lastUpdate']}:" style="font-weight:bold"/>
<h:outputText id="lastUpdate" value="#{job.formattedDate(job.lastUpdate)}" />
<p:outputLabel for="toProcess" value="#{MessageResources['text.itemsToProcess']}:" style="font-weight:bold"/>
<h:outputText id="toProcess" value="#{job.itemsToProcess}" />
<p:outputLabel for="endDate" value="#{MessageResources['text.ended']}:" style="font-weight:bold"/>
<h:outputText id="endDate" value="#{job.formattedDate(job.endedDate)}" />
<p:outputLabel for="processed" value="#{MessageResources['text.itemsProcessed']}:" style="font-weight:bold"/>
<h:outputText id="processed" value="#{job.itemsProcessed}" />
<p:outputLabel for="status" value="#{MessageResources['text.state']}:" style="font-weight:bold"/>
<h:outputText id="status" value="#{job.status}" />
</p:panelGrid>
</h:panelGroup>
</p:outputPanel>
<p:spacer width="5"/>
<p:separator />
<p:spacer width="5"/>
</p:dataGrid>
My RequestScope backing bean...
#Named("progressController")
#RequestScoped
public class ProgressController
{
#EJB
private EJBJobRepositoryLocal ejbJobRepository;
public Long progress(DMJob jobExecution) throws VfCmsSqlException
{
if (jobExecution.getStatus().equals(BatchStatus.STARTED.name())) {
jobExecution.setProgress(ejbJobRepository.getJobProgress(jobExecution.getExecutionId()));
}
PrimeUtil.get().update("formExecutions:jobInfo");
return jobExecution.getProgress();
}
public void onCompleteJob(DMJob jobExecution)
{
Object[] parameters = {jobExecution.getName(), jobExecution.getExecutionId()};
Messages.displayInfoMessage("text.jobComplete", parameters);
}
}
Ok. The problem is that the PrimeFaces().start() method is not been executed over all the components generated by JSF. So, what I did is a javascript function which is executed when the page is fully loaded. In my case the components that I needed to initialize are several progress bar. My components are inside a data scroller which is inside a form, that's why I concat those id's. The 'i' is the index of each of the rendered progress bar in the page.
<script type="text/javascript">
$(window).load(function() {
startProgress();
});
function startProgress(){
var pid = document.getElementsByClassName('ui-progressbar');
var pidLength = pid.length;
for (var i = 0; i < pidLength; i++) {
var id = "formExecutions:scroller:".concat(i).concat(":progressBar");
PrimeFaces.getWidgetById(id).start();
}
}
</script>
And that was all!
I have a data-table (p:datatable) with filters and an action button on each row. Now when I click on action button, wrong data is passed to the bean.
Actually when Edit button is clicked, startupdate method of the bean is called and an argument is passed to it.
In normal cases, without any filter, right employee gets passes and the dialog box opens and shows correct values. However when I apply filter, It's always the first row which gets passed and the dialog box opens and show details of the employee of first row.
I do have rowKey set.
<h:form id="wrapform">
<p:dataTable style="margin-top:20px" widgetVar="emptable" id="empdata" var="emp" rowKey="#{emp.empdto.id}" value="#{employeeMaintainanceController.allUsersWithDetails}" filteredValue="#{employeeMaintainanceController.allUsersWithDetails_filtered}">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search in any column:" />
<p:inputText id="globalFilter" onkeyup="emptable.filter()" style="width:150px; margin-left: 10px;" />
</p:outputPanel>
</f:facet>
<p:column headerText="Employee-Id" filterBy="#{emp.userdto.id}" filterMatchMode="contains">
<h:outputText value="#{emp.userdto.id}" />
</p:column>
<p:column headerText="First Name" filterBy="#{emp.userdto.firstName}" filterMatchMode="contains">
<h:outputText value="#{emp.userdto.firstName}" />
</p:column>
<p:column headerText="Last Name" filterBy="#{emp.userdto.lastName}" filterMatchMode="contains">
<h:outputText value="#{emp.userdto.lastName}" />
</p:column>
<p:column headerText="E-mail">
<h:outputText value="#{emp.userdto.email}" />
</p:column>
<p:column headerText="Date of Joining">
<h:outputText value="#{emp.empdto.doj}" />
</p:column>
<p:column headerText="Team" filterMatchMode="contains" filterBy="#{teamMaintainanceController.getTeamById(emp.empdto.teamid)}">
<h:outputText value="#{teamMaintainanceController.getTeamById(emp.empdto.teamid)}" />
</p:column>
<p:column headerText="Office" filterBy="#{employeeMaintainanceController.getLocName(emp.userdto.primaryOfficeSeq)}" filterMatchMode="contains">
<h:outputText value="#{employeeMaintainanceController.getLocName(emp.userdto.primaryOfficeSeq)}" />
</p:column>
<p:column headerText="Is Active?">
<h:outputText value="#{(emp.empdto.dor == null)?'Active':'Already Resigned'}" />
</p:column>
<p:column headerText="Edit">
<p:commandButton value="Edit/Move/Delete"
title="Edit"
actionListener="#{employeeMaintainanceController.startUpdate(emp)}"
ajax="true" process="#this" oncomplete="dlg2.show();" update=":entryform"/>
</p:column>
</p:dataTable>
</h:form>
<p:dialog header="Change Employee Details, Move him to different Teams, Transfer him to different Locations" widgetVar="dlg2" modal="true" >
<h:form id="entryform">
<table id="empdatatable">
<p:growl id="growl" showDetail="true"/>
<tr><td><p:outputLabel for="searchedid" value="ID" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><h:outputText id="searchedid" value="#{employeeMaintainanceController.wrapemp.userdto.id}"></h:outputText></td></tr>
<tr><td><p:outputLabel for="searchedfname" value="First Name" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><h:outputText id="searchedfname" value="#{employeeMaintainanceController.wrapemp.userdto.firstName}"></h:outputText></td></tr>
<tr><td><p:outputLabel for="searchedlname" value="Last Name" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><h:outputText id="searchedlname" value="#{employeeMaintainanceController.wrapemp.userdto.lastName}"></h:outputText></td></tr>
<tr><td><p:outputLabel for="searchedemail" value="E-Mail" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><h:outputText id="searchedemail" value="#{employeeMaintainanceController.wrapemp.userdto.email}"></h:outputText></td></tr>
<tr><td><p:outputLabel for="loc" value="Office Location" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><p:selectOneMenu id="loc" value="#{employeeMaintainanceController.wrapemp.userdto.primaryOfficeSeq}" rendered="#{employeeMaintainanceController.wrapemp !=null}">
<f:selectItem itemLabel="Select One" itemValue="-1" />
<f:selectItems value="#{employeeMaintainanceController.officeList}" var="theme" itemLabel="#{theme.name}" itemValue="#{theme.seq}"/>
</p:selectOneMenu></td></tr>
<tr><td><p:outputLabel for="searcheddoj" value="Date Of Joining" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><h:outputText id="searcheddoj" value="#{employeeMaintainanceController.wrapemp.empdto.doj}"></h:outputText></td></tr>
<tr><td><p:outputLabel for="cal1" value="Date Of Resignation" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><p:calendar id="cal1" value="#{employeeMaintainanceController.wrapemp.empdto.dor}" rendered="#{employeeMaintainanceController.wrapemp !=null}" /></td></tr>
<tr><td><p:outputLabel for="chk_isadmin" value="IS Admin?" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><p:selectBooleanCheckbox id="chk_isadmin" value="#{employeeMaintainanceController.isadmin}" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:selectBooleanCheckbox> </td></tr>
<tr><td><p:outputLabel for="sel_team" value="TeamName" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:outputLabel></td><td><p:selectOneMenu id="sel_team" value="#{employeeMaintainanceController.wrapemp.empdto.teamid}" rendered="#{employeeMaintainanceController.wrapemp !=null}">
<f:selectItem itemLabel="Select One" itemValue="-1" />
<f:selectItems value="#{teamMaintainanceController.allTeams}" var="theme" itemLabel="#{theme.name}" itemValue="#{theme.id}"/>
</p:selectOneMenu></td></tr>
<tr><td><p:commandButton value="Edit" ajax="false" actionListener="#{employeeMaintainanceController.updateemp}" update=":wrapform" oncomplete="dlg2.hide();" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:commandButton></td><td><p:commandButton value="Delete This Employee" ajax="false" actionListener="#{employeeMaintainanceController.deleteemp}" update=":wrapform" oncomplete="dlg2.hide();" rendered="#{employeeMaintainanceController.wrapemp !=null}"></p:commandButton></td></tr>
</table>
</h:form>
</p:dialog>
UPDATE
The problems more weird. The problem appears only when the number of filtered row is just one. Anything else and it works fine.
In following code Cheque Amount is less then (quautity * rate) then display alert message.
XHTML code :
<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>
Following managed bean code it is used to store transaction related data :
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();
}
}
Then after transaction data store otherwise not.
put In the else part
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;
I'm use Primefaces and trying to create infoWindow with different content for different types of overlays.
Map.java
public void onMarkerSelect(OverlaySelectEvent event) {
if (event.getOverlay() instanceof Marker) {
selectedOverlay = "marker";
selMarkerSite = (Site) event.getOverlay().getData();
selMarkerSiteNetworkElements = new ArrayList<NetworkElement>();
List<NetworkElement> neList = selMarkerSite.getNetworkElements();
if (!neList.isEmpty()) {
for (NetworkElement ne : neList) {
if (!(ne.getNeFunc().getName().equals("CELL2G") || ne.getNeFunc().getName().equals("CELL3G") || (ne.getNeStatus() != null && ne.getNeStatus().getId().equals(new BigDecimal(26))))
&& filter.getRadioType().contains(ne.getNeFunc().getGeneration())) {
selMarkerSiteNetworkElements.add(ne);
}
}
}
balloonText = HtmlFormatter.siteBalloonInfoFormater(selMarkerSite);
}
if (event.getOverlay() instanceof Polygon) {
selectedOverlay = "polygon";
// my code
}
}
jsf
<p:gmap center="#{map.center}"
zoom="#{map.zoom}" fitBounds="false" type="HYBRID" id="mainMapId"
style="width:100%; height:100%" widgetVar="mainMap"
model="#{map.mapModel}">
<p:ajax event="overlaySelect" listener="#{map.onMarkerSelect}" />
<p:ajax event="stateChange" listener="#{map.onStateChange}"
global="false"/>
/>
<p:gmapInfoWindow>
<p:panel rendered="#{map.selectedOverlay=='marker'}">
<h:panelGrid columns="2" width="580">
<p:column style="width:200px">
<p:outputPanel style="display:block; width:180px">
<h:outputText value="#{map.balloonText}" escape="false" />
<h:panelGrid columns="2" style="width:180px">
<p:commandLink id="getAlarmsForSite"
actionListener="#{map.getSiteAlarms}">
<h:outputText value="Alarms" />
</p:commandLink>
<p:commandLink id="editSiteOnMapBtn"
actionListener="#{map.editSite()}">
<f:setPropertyActionListener
target="#{createOrUpdateSiteDialogController.componentsToUpdateOnNetworkElementSelectListener}"
value=":updateOrCreateNetworkElementDialogId" />
<h:outputText value="Edit this Site" />
</p:commandLink>
</h:panelGrid>
</p:outputPanel>
</p:column>
<p:column style="width:380px">
<p:tabView id="tabView" var="NE"
value="#{map.selMarkerSiteNetworkElements}"
rendered="#{map.selMarkerSiteNetworkElements.size()>0}">
<p:tab id="neTab" title="#{NE.name}"
titleStyleClass="tabSev#{NE.minSeverity}">
<h:panelGrid columns="2" style="width: 420px;">
<h:panelGrid columns="2" style="width: 230px;">
<h:outputText value="MO: " style="font-weight: bold" />
<h:outputText value="#{NE.managingElement.name}" />
<h:outputText value="DN: " style="font-weight: bold" />
<h:outputText value="#{NE.dn}" />
<h:outputText value="TYPE: " style="font-weight: bold" />
<h:outputText value="#{NE.neFunc.name}" />
<h:outputText value="STATUS: " style="font-weight: bold" />
<h:outputText value="#{NE.neStatus.nameEng}" />
<h:outputText value="Customer " style="font-weight: bold" />
<p:graphicImage width="18" cache="true"
title="#{NE.nms.customer.nameEng}"
url="#{NE.nms.customer.labelSmall}"
style="padding-top: 2px;" />
<p:commandLink id="getAlarmsForNE"
actionListener="#{map.getBsAlarms(NE)}">
<h:outputText
value="Alarms (#{NE.sizeAlarmsWithChildrenNE})"
styleClass="sev#{NE.minSeverity}" />
</p:commandLink>
<p:commandLink id="editNeOnMapBtn"
actionListener="#{map.editNe(NE)}">
<h:outputText value="Edit this NE" />
<f:setPropertyActionListener
target="#{createOrupdateNetworkElementController.componentsToUpdateOnSiteViweActionListener}"
value=":updateOrCreateSiteDialogId" />
</p:commandLink>
</h:panelGrid>
<p:dataList value="#{NE.networkElements}" var="NEc"
rendered="#{NE.networkElements.size()>0}">
<h:outputText
value="name: #{NEc.name}; azimuth: #{NEc.azimuth!=null ? NEc.azimuth : '-' }" />
</p:dataList>
</h:panelGrid>
</p:tab>
</p:tabView>
</p:column>
</h:panelGrid>
</p:panel>
<p:panel rendered="#{map.selectedOverlay=='polygon'}">
//
</p:panel>
</p:gmapInfoWindow>
</p:gmap>
The troubleis that the infoWindow is not showed when i click on any overlay except marker.
I want use jsf code in infoWindow.
How i can show infoWindow for another overlays?
Command button onclick event is not working its not invoking Banking bean Method. There are some other commandButtons like
action="#{editBean.editQuestionAction}"
action="#{editBean.addNewQuestionAction}"
were working fine but its not in the case of `action="#{editBean.updateQuestionAction}"
<p:tab title="Questions">
<h:outputText value="Select a project to add questions: " />
<h:selectOneMenu id="projects_dpd" value="#{editBean.currentProject.projectId}" onchange="">
<f:selectItems value="#{projectBean.projects}" />
</h:selectOneMenu><br/>
<h:form id="listForm">
<p:panel id="listPanel" header="List of Questions" toggleable="false" closable="false">
<p:dataList paginatorAlwaysVisible="false" paginatorPosition="bottom" effect="slide"
value="#{editBean.editBeanList}" var="q"
paginator="true" rows="5" effectSpeed="fast"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<p:commandButton action="#{editBean.**editQuestionAction**}" update="editPanel" title="Edit Question" image="edit">
<f:setPropertyActionListener value="#{q}" target="#{editBean.editQuestion}" />
</p:commandButton>
<p:spacer width="30" height="30" />
<h:outputText value="#{q.question.questionId} -> #{q.question.questionText} ->"/> <b><h:outputText value="#{q.question.questionType}" /></b>
</p:column>
</p:dataList>
<p:commandButton value="New Question !!" action="#{editBean.**addNewQuestionAction**}" update="editPanel" />
<p:commandButton ajax="false" value="Home Page !!" action="#{indexBean.**gotoHomePage}**" />
</p:panel>
</h:form>
<p:layoutUnit position="center" scrollable="true">
<p:panel id="editPanel" header="Edit Section" toggleable="false" closable="false" >
<h:form id="form">
<table cellspacing="20">
<tr>
<td><h:outputLabel value="Question Text:" /></td>
<td><p:inputTextarea id="questionText" required="true" value="#{editBean.editQuestion.question.questionText}" autoResize="true" effectDuration="400" maxHeight="100" /></td> <td><p:message for="questionText" /></td>
</tr>
<tr>
<td>Review:</td>
<td><p:inputTextarea id="reviewText" required="true" value="#{editBean.editQuestion.question.reviewText}" autoResize="true" effectDuration="400" maxHeight="100" /></td>
<td><p:message for="reviewText" /></td>
</tr>
<tr>
<td>Option Type:</td>
<td>
<h:selectOneRadio label="Option Type" value="#{editBean.editQuestion.question.optionType}">
<f:selectItem itemLabel="Currency" itemValue="currency" />
<f:selectItem itemLabel="Hours" itemValue="hours" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td>Question Type:</td>
<td>
<h:selectOneRadio label="Question Type" value="#{editBean.editQuestion.question.questionType}">
<f:selectItem itemLabel="Mandatory" itemValue="mandatory" />
<f:selectItem itemLabel="Linked" itemValue="linked" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td align="right">
<h:selectBooleanCheckbox label="Hide Weight until Review !!" value="#{editBean.editQuestion.question.hideWeight}" />
</td>
<td>Hide Weight Until Review</td>
</tr>
<tr>
<td>Options:</td>
<td>
<p:panel header="Add Option">
<h:panelGrid columns="2" id="grid">
<h:outputLabel value="Text : " for="txt_title"></h:outputLabel>
<p:inputText id="txt_title"
value="#{editBean.placeHolderForOption.optionText}" />
<h:outputLabel value="Weight : " for="txt_author"></h:outputLabel>
<p:inputText id="txt_author"
value="#{editBean.placeHolderForOption.weight}" />
<p:commandButton value="Reset" type="reset"/>
<p:commandButton value="Add" update="options #parent"
action="#{editBean.initOption}" >
<p:collector value="#{editBean.placeHolderForOption}"
addTo="#{editBean.editQuestion.options}" />
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:outputPanel id="options">
<p:dataTable value="#{editBean.editQuestion.options}" var="opt">
<p:column headerText="Text" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.optionText}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.optionText}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Weight" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.weight}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.weight}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Linked Question" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.linkedQuestionId}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{opt.linkedQuestionId}">
<f:selectItems value="#{editBean.linkedQuestionIds}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Display Order" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.displayOrder}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.displayOrder}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Operation" />
</f:facet>
<p:commandLink value="Remove" update="form:options" process="#this">
<p:collector value="#{opt}"
removeFrom="#{editBean.editQuestion.options}" />
</p:commandLink>
<p:spacer width="10" />
<p:rowEditor />
</p:column>
</p:dataTable>
</p:outputPanel>
</td>
</tr>
</table>
<p:commandButton ajax="false" value="Update Question" action="#{editBean.updateQuestionAction}"
rendered="#{editBean.operation eq 'edit'}" />
<p:commandButton ajax="false" value="Add Question" update="msgs listForm:listPanel" action="#{editBean.saveQuestion}"
rendered="#{editBean.operation eq 'add'}">
<p:collector value="#{editBean.editQuestion}"
addTo="#{editBean.editBeanList}" />
</p:commandButton>
<p:commandButton ajax="false" value="Delete Question" update="msgs listForm:listPanel" action="#{editBean.deleteQuestionAction}"
rendered="#{editBean.operation eq 'edit'}">
<p:collector value="#{editBean.editQuestion}"
removeFrom="#{editBean.editBeanList}" />
</p:commandButton>
</h:form>
</p:panel>
</p:layoutUnit>
</p:tab>
Its not getting executing when i click on button
#ManagedBean
#RequestScoped
public class EditBean {
#ManagedProperty(value = "#{questionDao}")
private QuestionDao questionDao;
private String operation;
private QuestionHelper editQuestion;
private SelectItem[] linkedQuestionIds;
private List<QuestionHelper> linkedQuestions = new ArrayList<QuestionHelper>();
private List<QuestionHelper> allQuestions = new ArrayList<QuestionHelper>();
public void editQuestionAction() {
operation = "edit";
}
public void deleteQuestionAction() {
questionDao.delete(editQuestion.getQuestion());
listBean.getListOfQuestions().remove(editQuestion);
addNewQuestionAction();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Deleted !"));
}
public void updateQuestionAction() {
editQuestion.getQuestion().getOptionses().clear();
for (Options o : editQuestion.getOptions()) {
o.setQuestions(editQuestion.getQuestion());
editQuestion.getQuestion().getOptionses().add(o);
}
getQuestionDao().update(editQuestion.getQuestion());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Updated !"));
}
Hi I found answer for my question, The command button is not working because of rendered tag and Request scope of managed bean , as on every subsequent request after pressing command button my request scoped (iseditable ) is getting resetting. When i made it Session scoped its working Fine.