Issue with resetting datagrid in primefaces - jsf

I am new to JSF and I am working on an application where a group of parameters placed in a datagrid can be either added or removed. Below is the initial level of screenshot:
When I click on RemoveInvoice of any of the existing list, the list present after that box should automatically take the position of the removed list. But in my case, a blank section is getting displayed as per the below screenshot:
My jsf code looks like:
<div class="listing_Table">
<p:dataGrid columns="3" layout="grid" id="addInvoicePanel"
value="#{hrOrganizationPaymentDetailBean.invoiceDetailTOList}"
var="invoiceDetail">
<p:panelGrid rendered="#{!invoiceDetail.delete}">
<div class="Table">
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceType:</p:outputLabel>
</div>
<div class="Cell">
<p:selectOneMenu value="#{invoiceDetail.invoiceTypeID}"
filter="true" filterMatchMode="contains" required="true"
requiredMessage="InvoiceType is required">
<f:selectItems
value="#{hrOrganizationPaymentDetailBean.newInvoiceTypeList}"
var="list" itemValue="#{list.typeId}"
itemLabel="#{list.type}" />
</p:selectOneMenu>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceNumber:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoiceNumber}"
required="true" requiredMessage="InvoiceNumber is required" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceAmount:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoiceAmount}"
required="true" requiredMessage="InvoiceAmount is required">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>InvoicePath:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoicePath}" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceDate:</p:outputLabel>
</div>
<div class="Cell">
<p:calendar id="invoiceDate"
value="#{invoiceDetail.invoiceDate}" showOn="button"
readonlyInput="true" timeZone="IST" pattern="dd-MMM-yyyy"
required="true" requiredMessage="InvoiceDate is required" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel value="ServiceTax:" />
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.serviceTax}">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel value="TDS:" />
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.tDS}">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell"></div>
<div class="Cell">
<p:commandButton styleClass="Submit_button"
value="Remove Invoice"
action="#{hrOrganizationPaymentDetailController.removeInvoiceDetail(invoiceDetail)}"
update=":EditOrganizationPaymentDetailForm:addInvoicePanel" />
</div>
</div>
</div>
</p:panelGrid>
</p:dataGrid>
</div>
And my backend java code is:
public void removeInvoiceDetail(InvoiceDetailTO invoiceDetailTO)
{
List<InvoiceDetailTO> invoiceDetailTOList = null;
List<Long> deletedInvoiceDetail = null;
try {
invoiceDetailTOList = hrOrganizationPaymentDetailBean.getInvoiceDetailTOList();
deletedInvoiceDetail = hrOrganizationPaymentDetailBean.getDeletedInvoiceDetailID();
if (deletedInvoiceDetail != null && !deletedInvoiceDetail.isEmpty()) {
} else {
deletedInvoiceDetail = new ArrayList<Long>();
}
for (InvoiceDetailTO detailTO : invoiceDetailTOList) {
if ((detailTO.getInvoiceDetailID() != null && detailTO.getInvoiceDetailID().equals(invoiceDetailTO.getInvoiceDetailID()))
|| (detailTO.getUniqueID() != null && detailTO.getUniqueID().equals(invoiceDetailTO.getUniqueID()))) {
detailTO.setDelete(true);
if (invoiceDetailTO.getInvoiceDetailID() != null) {
deletedInvoiceDetail.add(invoiceDetailTO.getInvoiceDetailID());
}
}
}
hrOrganizationPaymentDetailBean.setInvoiceDetailTOList(invoiceDetailTOList);
hrOrganizationPaymentDetailBean.setDeletedInvoiceDetailID(deletedInvoiceDetail);
} catch (Exception e) {
LOGGER_.error("", e);
}
}
Please advise where I am making a mistake?

The problem is in <p:panelGrid rendered="#{!invoiceDetail.delete}">. Even with rendered="false" cell won't be removed from html page after rendering. If you open debugger in your browser (press F12 for Mozilla or Chrome) you can find empty cell there <td class="ui-datagrid-column"></td>. So you need to remove deleted item from your #{hrOrganizationPaymentDetailBean.invoiceDetailTOList} and update dataGrid.

Related

How to change enable/disable a <p:calendar> and an <p:inputTextarea> when a <p:selectBooleanCheckbox> is checked or not, using primefaces?

I have this part of code:
<!-- /row -->
<div class="row" style="margin-top: 15px">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Ημερομηνία Ανάκλησης Ποινής</label>
<div class="controls span7">
<p:calendar id="recallDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy"
value="#{penaltiesView.penalty.recallDate}" disabled="true"/>
<i class="fa fa-calendar hcg-input-icon"></i>
</div>
</div>
</div>
<!-- /span -->
</div>
<!-- /row -->
<div class="row" style="margin-top: 15px">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Σχόλια Ανάκλησης Ποινής</label>
<div class="controls span7">
<p:inputTextarea rows="6" id="recallComments" styleClass="hcg-full-width" value="#{penaltiesView.penalty.recallComments}" disabled="true"/>
</div>
</div>
</div>
<!-- /span -->
</div>
<!-- /row -->
<div class="row">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Ανάκληση - Ολοκλήρωση Πειθαρχικής Ποινής</label>
<div class="controls span7">
<p:selectBooleanCheckbox id="RevocationOrCompletion" styleClass="hcg-checkbox margin-bottom-10" value="#{penaltiesView.penalty.revocationOrCompletion}" disabled="#{!penaltiesView.canEdit()}" >
<p:ajax event="change" update="recallDate,recallComments"/>
</p:selectBooleanCheckbox>
</div>
</div>
</div>
<!-- /span -->
</div>
which produces the following components:
Now, what I want to do, is to make the calendar component and the Textarea to get enabled when I check the checkBox and if I uncheck it, they must be disabled again. The use of javascript due to requirements is not a valid way. I am having some difficulties on how to make this happen.
Any suggestions are appreciated.
Thank you in advance.
Your elements can't be updated because you have in your code disabled=true for calendar and textArea. If you want to change disable parameter depending on boolean checkbox than disabled value needs to be a value of boolean checkbox. Your boolean field also needs to have geters and setters.
<p:calendar id="recallDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy"
value="#{penaltiesView.penalty.recallDate}" disabled="#{penaltiesView.penalty.revocationOrCompletion}"/>
<p:inputTextarea rows="6" id="recallComments" styleClass="hcg-full-width" value="#{penaltiesView.penalty.recallComments}" disabled="#{penaltiesView.penalty.revocationOrCompletion}"/>
<p:selectBooleanCheckbox id="RevocationOrCompletion" styleClass="hcg-checkbox margin-bottom-10" value="#{penaltiesView.penalty.revocationOrCompletion}" disabled="#{!penaltiesView.canEdit()}" >
<p:ajax update="recallDate recallComments" process="#this"/>
</p:selectBooleanCheckbox>

updating bean when change selectonemenu value without refreshing the page

I have selectonemenu and i want when i change the value of selectonemenu i want that the bean value updated for to display some code that i have in a block condition without submitting and refreshing the page without this i will lose the other value fill in the form
I have none display
I have selectonemenu block
<h:selectOneMenu id="categorieSelect" value = "#{categorie.option}"
valueChangeListener="#{categorie.categorieChanged}">
<f:selectItem itemValue="selection" itemLabel="Choisissez une catégorie" noSelectionOption="true"/>
<f:selectItems value ="#{categorie.options}" var="categorieSelect" />
<f:ajax event="change" execute="#form"/></h:selectOneMenu>
I have also some block in c:choose which i want to display when the value of selectonemenu change
<c:choose>
<c:when test="#{categorie.option == 'offreemploi'}">
<div class="row">
<p:outputLabel value="Type d'annonce *" class="outputelement" id="test3"></p:outputLabel>
</div>
<div class="row">
<h:selectOneRadio id="typeannonce" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="Le type d'annonce est obligatoire"
class="inputelement"
value="#{offreEmploi.typeannonce}" binding="#{typeannonce}">
<f:selectItem itemValue="demande" itemLabel="Demande (Vous recherchez un emploi)"
/>
<f:selectItem itemValue="offre" itemLabel="Offre (Vous recherchez un employé)" />
</h:selectOneRadio>
</div>
<div class="row">
<h:message for="typeannonce" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText value="Intitulé du poste *" class="outputelement"></h:outputText>
</div>
<div class="row">
<h:inputText id="intituleposte" binding="#{intituleposte}" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="L'intitule du poste est obligatoire"
class="col-xs-12 col-sm-6 col-md-6 col-lg-6 inputelement"
value="#{offreEmploi.intituleposte}"></h:inputText>
</div>
<div class="row">
<h:message for="intituleposte" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText value="Description du poste *" class="outputelement"></h:outputText>
</div>
<div class="row">
<h:inputTextarea id="descriptionposte" rows="10" cols="30" binding="#{descriptionposte}" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="La description du poste est obligatoire"
class="col-xs-12 col-sm-6 col-md-6 col-lg-6 inputelement"
value="#{offreEmploi.descriptionposte}"></h:inputTextarea>
</div>
<div class="row">
<h:message for="descriptionposte" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photos : Une annonce avec photos est beaucoup plus consulté qu'une annonce sans photos"></h:outputText>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo principal"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo1}" binding="#{photo1}"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo 2"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo2}" binding="#{photo2}"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo 3"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo3}" binding="#{photo3}"/>
</div>
</c:when>
<c:otherwise>Bonjour</c:otherwise>
</c:choose>
and here is my backing bean
#ManagedBean
#SessionScoped
public class Categorie implements Serializable{
String option; // +getter +setter
List<SelectItem> options; // +getter
public String getOption() {
return option;
}
public void setOption(String selectedOption) {
this.option = selectedOption;
}
public List<SelectItem> getOptions() {
return options;
}
public void setOptions(List<SelectItem> options) {
this.options = options;
}
public void categorieChanged(ValueChangeEvent e) {
//assign new value to country
option = e.getNewValue().toString();
}
public void changeCountry() {
//System.out.println("Selected country is: " + option.);
}
public Categorie() {
options = new ArrayList<SelectItem>();
SelectItemGroup group1 = new SelectItemGroup("EMPLOI");
group1.setSelectItems(new SelectItem[] {
new SelectItem("offreemploi", "Offre d'emploi")
});
options.add(group1);
}
public void save(){
}
}

Primefaces avoid submitting multiple forms

I am new to Primefaces and I am working on a requirement to open a dialog box when we click on the button.
I could able to open the dialog and submit the form. But here I am facing a new that form behind the modal dialog also get submitted when I am trying to submit the form in the modal. The form behind the modal is a pure html code and modal dialog form is written in primefaces.
Is there any chances to submit the form that is existing in the dialog and skip the form behind the dialog. Could anyone tell me the solution for this?
For clear understanding, I am submitting the code below
<form class="form-horizontal" action="${request.contextPath}/appLogin" role="form" method="POST" h:rendered="true">
<div class="form-group">
<div class="col-sm-12" align="center">
<font color="red"> <h:outputLabel
value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
</font>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="username">Username</label> <input type="text"
class="form-control" name="username" id="username"
placeholder="Enter your username" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="pwd">Password</label> <input type="password"
class="form-control" name="password" id="password"
placeholder="Enter password" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6">
<input type="checkbox" name="remember" id="remember" />
<h:outputText value=" Remember Me" />
</div>
<div class="col-sm-6" align="right">
<p:commandLink value="Forgot Password?" id="loginforgotpasswordlink"
onclick="clearEmailForgotPasswordPopUp();" />
</div>
</div>
</div>
</div>
</form>
<p:dialog id="emailIdDialog" modal="true" widgetVar="emailIdDialog" width="400"
header="Email Id" appendTo="#(body)" resizable="false">
<ui:include src="/faces/validateEmailId.xhtml" />
</p:dialog>
<div class="form-group">
<p:outputLabel for="emailid1" value="Email" class="col-sm-3 control-label align-right" style="border: 0px solid green;padding-right: 0px;text-align: right;"></p:outputLabel>
<div class="col-sm-9" style="border: 0px solid red;padding-left:0px;">
<p:inputText type="text" id="emailid1"
name="emailid1" required="true" requiredMessage="Please enter an email address"
placeholder="Enter your email id" style="width:100%"/>
</div>
<p:spacer height="10px"></p:spacer>
<div class="text-right" style="padding-left: 0px;">
<p:commandButton value="Submit" update="messages,:emailIdValidation" style="float: right; margin-right: 15px;">
<f:actionListener binding="#{someClassBean.validateEmail()}" />
</p:commandButton>
</div>
</div>
</h:form>
When I am clicking the form submit button in modal dialog the other form also getting submitting.

when i try to refresh a form component from another form using <p:ajax update=""/> it shows error "Cannot find component [duplicate]

This question already has answers here:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
(6 answers)
Closed 4 years ago.
Can any one help me out of my problem? though i have been seen semilar problem from this site but i'm unable to fix my problem. here is my code..
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<meta charset="utf-8"/>
<meta name="viewport" content="width=device.width, initial-scale=1"/>
<meta http-equiv="X-UA-Conpatible" content="IE=edge"/>
<h:outputStylesheet library="css" name="bootstrap.css"/>
<link href="resources/css/w3.css" rel="stylesheet" type="text/css"/>
<link href="resources/css/w3-theme-teal.css" rel="stylesheet" type="text/css"/>
<div class="panel panel-info">
<!-- Default panel contents -->
<div class="panel-heading">Student Wise Fees Collection Details</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<div class="panel panel-info" >
<div class="panel-heading">Payment Details</div>
<div class="panel-body">
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-top: 4%">
<h:form id="form1">
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1" style="color: blue;">Student Id:</span>
<p:inputText id="student_id" value="#{controllerBean.selectedfee.stuId}" type="text" readonly="true" style="width: 85%; color: blue;" class="form-control" placeholder="Student Id"/>
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Name:</span>
<p:inputText id="stname" type="text" readonly="true" value="#{controllerBean.selectedfee.name}" class="form-control" placeholder="Name of the student" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Program:</span>
<p:inputText id="pname" type="text" readonly="true" value="#{controllerBean.selectedfee.program}" class="form-control" placeholder="Program Name" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Session:</span>
<p:inputText id="s_name" type="text" readonly="true" value="#{controllerBean.selectedfee.session}" class="form-control" placeholder="Session Name" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Recept No:</span>
<p:inputText id="recptno" type="text" value="#{controllerBean.selectedfee.recptNo}" readonly="true" class="form-control" placeholder="Recept Number" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Amount:</span>
<p:inputText id="a_mnt" type="text" value="#{controllerBean.selectedfee.amount}" readonly="true" class="form-control" placeholder="Paid Amount" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1" style="color: green;">Voucher:</span>
<p:inputText id="voucher" type="text" value="#{controllerBean.selectedfee.AIBLVoucher}" readonly="true" style="color: green;" class="form-control" placeholder="AIBL Voucher Number" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 4%;">
<span class="input-group-addon" id="sizing-addon1" style="color: red;">AUB Token:</span>
<p:inputText id="aub_token" type="text" value="#{controllerBean.selectedfee.stud_pay_rec_mid}" style="color: red;" readonly="true" class="form-control" placeholder="AUB TXN ID Number" />
</div>
</h:form>
</div>
</div>
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9" >
<div class="col-lg-12 col-md-12 col-sm-12" >
<div class="panel panel-info">
<div class="panel-heading">Student's Payment Record</div>
<div class="panel-body">
<h:form id="form2">
<input type="text" class="form-control" id="task-table-filter" data-action="filter" data-filters="#task-table" placeholder="Filter Tasks" />
<p:dataTable class="table table-hover" value="#{controllerBean.listofunifees}" var="FEES_COLLECTION" selection="#{controllerBean.selectedfee}" id="task-table" rowKey="#{FEES_COLLECTION.stud_pay_rec_mid}" selectionMode="single" paginator="true" paginatorPosition="bottom" rows="7" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >
<p:ajax event="rowSelect" update=":form1" />
<p:column headerText="StuId" width="11%">
<h:outputText value="#{FEES_COLLECTION.stuId}" />
</p:column>
<p:column headerText="Student Name">
<h:outputText value="#{FEES_COLLECTION.name}" />
</p:column>
<p:column headerText="Program" width="15%">
<h:outputText value="#{FEES_COLLECTION.program}" />
</p:column>
<p:column headerText="Session" width="11%">
<h:outputText value="#{FEES_COLLECTION.session}" />
</p:column>
<p:column headerText="Rcpt No" width="10%">
<h:outputText value="#{FEES_COLLECTION.recptNo}" />
</p:column>
<p:column headerText="Amount" width="10%">
<h:outputText value="#{FEES_COLLECTION.amount}" />
</p:column>
<p:column headerText="Voucher" width="11%">
<h:outputText value="#{FEES_COLLECTION.AIBLVoucher}" />
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-top: 0px;">
<div class="col-lg-4 col-md-4 col-sm-4">
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h:form id="form3">
<button type="button" class="btn btn-success btn-sm col-lg-5 col-md-5 col-sm-5">Save</button>
<div class="col-lg-2 col-md-2 col-sm-2"></div>
<button type="button" class="btn btn-danger btn-sm col-lg-5 col-md-5 col-sm-5">Cancel</button>
</h:form>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
</div>
</div>
</div>
</div>
</div>
</ui:composition>
When i run this code, it shows javax.faces.FacesException: Cannot find component with expression ":form1:st_id" referenced from "centrepage:form2:task-table".
Now i've got my answer. The should be ":centrepage:form1:st_id, .., ..." and so on. bottom line is update="centrepage:form1:st_id". thanks for every one

PrimeFaces.cw does not show dialog content

When i use PrimeFaces.cw..
PrimeFaces.cw("Dialog","checkoutDlg",{
id:"j_idt115",
draggable:false,
resizable:false,
modal:true,
width:"auto",
maxWidth: „1083“,
showEffect:"blind",
hideEffect:"blind",
closeOnEscape:true,
fitViewport:true,
onShow:function(){
styleDialogCheckoutBtn()
}
});
..to show a dialog, I just see the lightbox, but the content does not appear.
<p:commandButton id="btnCheckOut" styleClass="btn btn-block btn-success" value="Add to card" process="#this"
oncomplete="PrimeFaces.cw('Dialog','checkoutDlg',{ id:'checkoutDlg', draggable:false, resizable:false, modal:true, width:'auto', maxWidth: '1083', showEffect:'blind', hideEffect:'blind', closeOnEscape:true, fitViewport:true, onShow:function(){styleDialogCheckoutBtn()} }); PF('checkoutDlg').initPosition(); PF('checkoutDlg').show(); return false;"/>
Dialog content:
<p:dialog widgetVar="checkoutDlg" id="checkoutDlg">
<div class="cart-items">
<div class="row-fluid cart-head-row clearfix">
<div class="col-xs-4">
<p class="text-bold">#{msg['dashboard.cart.checkout.service']}</p>
</div>
<div class="col-xs-4">
<p class="text-bold">#{msg['dashboard.cart.checkout.details']}</p>
</div>
<div class="col-xs-3 text-right">
<p class="text-bold">#{msg['dashboard.cart.checkout.price']}</p>
</div>
<div class="col-xs-1"></div>
</div>
</div>
</p:dialog>
Can anyone tell me how to show the content of the dialog in the lightbox?

Resources