PrimeFaces DataTable inCell Editing roweditevent - jsf-2

I've problem with datatable incell editing. My update query is running but updating old values. I'm using JDBC, PrimeFaces 3.4 GlassFish 3.1 JSF 2+. When I counted execute rows =1.
updated user and update_time is changing. But edited inputs values are not changing.
My xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<p:panel header="Ürün Ekleme Formu" toggleOrientation="vertical" toggleable="true">
<p:panelGrid columns="2">
<h:outputText value="Ürün Adı:"/><p:column><p:inputText value="#{urunlist.mahsul.urunAdi}" required="true" requiredMessage="Ürün adı?"/></p:column>
<h:outputText value="Tüik Kodu:"/><p:inputText value="#{urunlist.mahsul.tuikKodu}"/>
<h:outputText value="İva Kodu:"/><p:inputText value="#{urunlist.mahsul.tvaKodu}"/>
<h:outputText value="Üretim Dönemi:"/><p:autoComplete value="#{urunlist.mahsul.uretimDonemi}" completeMethod="#{urunlist.autoComplate(ud)}" var="ud_list" itemLabel="#{ud_list.uretimDonemi}" converter="javax.faces.Character" itemValue="#{ud_list}" forceSelection="false" multiple="false"/>
<h:outputText value="Üretim Şekli"/><p:inputText value="#{urunlist.mahsul.uretimSekli}"/>
<p:commandButton action="#{urunlist.urunKaydet()}" value="Kaydet" update="dataTable"/><input name="hiddo" type="hidden" value="#{login.kullaniciAdi}"/>
</p:panelGrid>
</p:panel>
</ui:insert>
</p:panel>
<p:panel id="viewPanel">
<ui:insert>view Layout</ui:insert>
</p:panel>
<p:panel id="updatePanel">
<ui:insert>Update Form</ui:insert>
</p:panel>
</p:panelGrid>
</div>
<div>
<p:outputPanel id="dataTable" >
<p:panel header="Ürünler">
<p:dataTable value="#{urunlist.urunGetir()}" var="u" paginator="true" rows="5" editable="true" sortOrder="true" draggableColumns="true" rowKey="#{u.urunKodu}">
<p:ajax event="rowEdit" listener="#{urunlist.urunGuncelle}" update=":mainForm:messages"/>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.urunKodu}"/>
</f:facet>
<f:facet name="input">
<input name="ukod" value="#{u.urunKodu}" type="hidden" disabled="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.tuikKodu}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{u.tuikKodu}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.tvaKodu}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{u.tvaKodu}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.urunAdi}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{u.urunAdi}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.uretimDonemi}(#{u.uretimSekli}-#{u.sulama})"/>
</f:facet>
<f:facet name="input">
<p:panelGrid columns="3">
<p:column>
<h:inputText size="2" value="#{u.uretimDonemi}" title="Üretim Dönemi"/>
</p:column>
<p:column>
<h:inputText size="2" value="#{u.uretimSekli}"/>
</p:column>
<p:column>
<h:inputText size="2" value="#{u.sulama}"/>
</p:column>
</p:panelGrid>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
#{u.ekleyen}
</p:column>
<p:column>
<h:outputText value="#{u.eklemeZamani}">
<f:convertDateTime pattern="dd.MMMM.yy--hh:mm:ss" timeZone="Turkey"/> </h:outputText>
</p:column>
<p:column>
<p:rowEditor/>
</p:column>
</p:dataTable>
</p:panel>
</p:outputPanel>
</div>
</h:form>
</ui:define>
My ManagedBean
public LoginBean getLoginned() {
return loginned;
}
public void setLoginned(LoginBean loginned) {
this.loginned = loginned;
}
public urunBean(){
mahsul=new urun();
loginned=new LoginBean();
}
public urun getMahsul() {
return mahsul;
}
public void setMahsul(urun mahsul) {
this.mahsul = mahsul;
}
public List<urun> urunGetir() throws SQLException{
try {
vk=DriverManager.getConnection("jdbc:postgresql://localhost:5432/uretim","postgres","Fa1276");
} catch (SQLException ex) {
System.out.println("DriverManager hatası "+ex);
}
PreparedStatement ps=vk.prepareStatement("select urun_kodu, tuik_kodu, iva_kodu, urun_adi, uretim_donemi, uretim_sekli, sulama, ekleyen, ekleme_zamani from urunler order by urun_kodu desc");
ResultSet sonuc=ps.executeQuery();
liste = new ArrayList<urun>();
while (sonuc.next()){
masul=new urun();
masul.setUrunKodu(sonuc.getLong("urun_kodu"));
masul.setTuikKodu(sonuc.getLong("tuik_kodu"));
masul.setTvaKodu(sonuc.getLong("iva_kodu"));
masul.setUrunAdi(sonuc.getString("urun_adi"));
masul.setUretimDonemi(sonuc.getString("uretim_donemi"));
masul.setUretimSekli(sonuc.getString("uretim_sekli"));
masul.setSulama(sonuc.getBoolean("sulama"));
masul.setEkleyen(sonuc.getString("ekleyen"));
masul.setEklemeZamani(sonuc.getTimestamp("ekleme_zamani"));
liste.add(masul);
}
return this.liste;
}
public void urunKaydet(){
String urunEkle=("insert into urunler(urun_kodu, tuik_kodu, iva_kodu, urun_adi, uretim_donemi, uretim_sekli, sulama, ekleyen, ekleme_zamani) values (nextval('urunler_urun_kodu_seq'),?,?,?,?,?,?,?, now())");
try {
PreparedStatement insert=vk.prepareStatement(urunEkle);
insert.setLong(1, mahsul.getTuikKodu());
insert.setLong(2,mahsul.getTvaKodu());
insert.setString(3,mahsul.getUrunAdi());
insert.setString(4,mahsul.getUretimDonemi());
insert.setString(5, mahsul.getUretimSekli());
insert.setBoolean(6,false);
insert.setString(7,session);
//insert.setString(9,java.sql.Timestamp);
//insert.executeQuery();
insert.executeUpdate();
insert.close();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( mahsul.urunAdi+" ürünü\nkaydedildi "));
//String selectInput= UIComponent.getCurrentComponent(null).getId().toString();
//System.out.println(selectInput);
}
catch (SQLException sqe){
System.out.println("sorguda hata var "+sqe);
}
}
public List<urun> autoComplate(urun ud) throws SQLException{
PreparedStatement udps=vk.prepareStatement("select uretim_donemi from urunler group by uretim_donemi");
ResultSet udset=udps.executeQuery();
List<urun> ud_list=new ArrayList<urun>();
while(udset.next()){
ud.uretimDonemi=udset.getString("uretim_donemi");
ud_list.add(ud);
}
/*
PreparedStatement usps=vk.prepareStatement("select uretim_sekli from urunler group by uretim_sekli");
ResultSet usset=usps.executeQuery();
List<urun> us_list=new ArrayList<urun>();
while(usset.next()){
urun us=new urun();
us.uretimSekli=usset.getString("uretim_sekli");
us_list.add(us);
return us_list;
}
*/
return ud_list;
}
public void urunGuncelle(RowEditEvent olay){
this.vk=vk;
urun urn=(urun)olay.getObject();
ExternalContext getirici=FacesContext.getCurrentInstance().getExternalContext();
String gullanici=getirici.getRequestParameterMap().get("hiddo");
//String gullanici=user.getKullaniciAdi();
Long id=(Long)urn.getUrunKodu();
System.out.println(id+"-"+gullanici);
try {
PreparedStatement urunguncelle=vk.prepareStatement("update urunler set urun_adi=?, uretim_donemi=?, uretim_sekli=?, guncelleyen=?, guncelleme_zamani=now() where urun_kodu=?");
urunguncelle.setString(1, urn.getUrunAdi());
urunguncelle.setString(2, urn.getUretimDonemi());
urunguncelle.setString(3, urn.getUretimSekli());
urunguncelle.setString(4, gullanici);
urunguncelle.setLong(5, id);
urunguncelle.executeUpdate();
int etkilenen=urunguncelle.executeUpdate();
if (etkilenen > 0) {
System.out.println(urn.getUrunAdi()+" adlı ürün güncellendi "+etkilenen+" satır.");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(urn.urunAdi+" adlı ürün güncellendi"));
System.out.println(urn.getUrunAdi()+" adlı ürün güncellendi!");
}else{
System.out.println("Güncelleme olmadı");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Güncelleme olmadı."));
}
urunguncelle.close();
vk.close();
} catch (SQLException ex) {
System.out.println("Güncelleme hatası "+ex);
}
}
/*
public void deneme(urun u){
String mesaj=("Ellediğiniz satırın id'si "+u.urunKodu+"!");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(mesaj));
}*/
}

I solved my problem. I overrideded boolean, hashcode and toString methods. I added a constructor my bean about my select query methods.

Related

Howto directly edit in p:datatable

i use Primefaces 5.1.
I have a datatable and want to edit directly in the cells.
It works, when i use editMode="row" with a p:rowEditor, but i want
to edit directly in cells without the rowEditor.
Wit editMode="cell" i get no CellEditEvent.
How is that possible?
best regards
Here is my JSF Page:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="${pageContext.request.contextPath}/templates/default.xhtml">
<ui:define name="content">
<h1>Hannymede Berechtigungsverwaltung</h1>
<p:panel header="Berechtigungsverwaltung">
<p:fieldset legend="Gruppe" style="margin-bottom:20px">
<h:form id="roleSelectorForm">
<p:selectOneMenu id="roleSelector" onchange="submit()"
value="#{authorityController.currentRole}"
converter="RoleConverter" hideNoSelectionOption="false">
<f:selectItem id="noRole" itemLabel="Gruppe auswählen"
itemValue="" noSelectionOption="true" />
<f:selectItems value="#{roleController.allRoles}" var="_role"
itemValue="#{_role}" itemLabel="#{_role.toString()}" />
</p:selectOneMenu>
</h:form>
</p:fieldset>
<p:fieldset legend="Berechtigungen der Gruppe"
style="margin-bottom:20px">
<h:form id="dataTableForm">
<p:dataTable id="authoritiesTable" editable="true" editMode="cell"
value="#{authorityController.currentRole.authoritys}" var="tw"
rowKey="#{tw.id} - #{tw.hashCode()}" rowIndexVar="rowIndex">
<p:ajax event="rowEdit"
listener="#{authorityController.authorityChanged}"></p:ajax>
<p:column sortBy="#{tw.voClassDesc.businessName}"
filterBy="#{tw.voClassDesc.businessName}">
<f:facet name="header">
<h:outputText value="Objekt" />
</f:facet>
<h:outputText value="#{tw.voClassDesc.businessName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Lesen" />
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{tw.autRead}" />
</f:facet>
<f:facet name="output">
<p:selectBooleanCheckbox value="#{tw.autRead}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Erstellen" />
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{tw.autInsert}" />
</f:facet>
<f:facet name="output">
<p:selectBooleanCheckbox value="#{tw.autInsert}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Ändern" />
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{tw.autUpdate}" />
</f:facet>
<f:facet name="output">
<p:selectBooleanCheckbox value="#{tw.autUpdate}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Löschen" />
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{tw.autDelete}" />
</f:facet>
<f:facet name="output">
<p:selectBooleanCheckbox value="#{tw.autDelete}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
</p:fieldset>
</p:panel>
</ui:define>
<ui:define name="title">Hannymede Berechtigungsverwaltung</ui:define>
</ui:composition>
Hello,
I did read the manual.
So looks my datatable in cellEdit Mode.
<p:dataTable id="authoritiesTable" editable="true" editMode="cell"
value="#{authorityController.currentRole.authoritys}" var="tw"
rowKey="#{tw.id} - #{tw.hashCode()}" rowIndexVar="rowIndex">
<p:ajax event="cellEdit"
listener="#{authorityController.authorityChanged}" update=":dataTableForm:authoritiesTable"></p:ajax>
and my Bean Method does not get the events
public void authorityChanged(CellEditEvent e) {
Object oldValue = e.getOldValue();
that's the table in "cellEdit" Mode - where i get no events.
best regards
When using editMode="cell" you need to use the cellEdit event instead of rowEdit. In addition, your ajax listener should be a bean method with the following signature: public void onCellEdit(CellEditEvent event)
So in your example, replace <p:ajax event="rowEdit" ... /> by <p:ajax event="cellEdit" ... /> and check your bean method
public void authorityChanged(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
References: PrimeFaces showcase and PrimeFaces 5.1 User Guide (pages 163 and 171)

I can't delete a row from datatable primefaces

I know this ask is repeated, but none response help me to solve this problem.
I'm trying to delete a row from a primefaces datatable with a commandButton and a confirmDialog, this doesn't work because the backBean isn't getting the values. When I'm trying to delete this show me a null pointer exception. well see my code if you can help me.
This is my XHTML:
<h:form id="principalForm">
<p:menubar>
<p:menuitem value="Nuevo" icon="ui-icon-plusthick" oncomplete="PF('wdlgIngresar').show();"/>
</p:menubar>
<p:dataTable id="dtpacientes" value="#{beanPersona.listPersona}" var="per"
paginator="true" rows="15" rowsPerPageTemplate="15,20,30" paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
selectionMode="single" selection="#{beanPersona.currPersona}" rowKey="#{per.id}">
<p:ajax event="rowSelect" listener="#{beanPersona.onRowSelect}" update=":dlgVer" oncomplete="PF('wdlgVer').show()" />
<p:column headerText="Id" sortBy="#{per.id}" filterBy="#{per.id}">
<h:outputText value="#{per.id}" />
</p:column>
<p:column headerText="Nombre" sortBy="#{per.nombres} #{per.apellidos}" filterBy="#{per.nombres} #{per.apellidos}">
<h:outputText value="#{per.nombres} #{per.apellidos}" />
</p:column>
<p:column headerText="Correo" sortBy="#{per.correo}" filterBy="#{per.correo}">
<h:outputText value="#{per.correo}" />
</p:column>
<p:column headerText="Edad" >
<h:outputText value="#{beanPersona.getEdad(per.nacimiento)}" />
</p:column>
<p:column headerText="Sexo" >
<h:outputText value="#{beanPersona.getSexo(per.sexo)}" />
</p:column>
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.nullMethod}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar paciente Nº #{beanPersona.currPersona.id} ?" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar(beanPersona.currPersona)}" />
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>
</h:form>
This is my Bean:
#ManagedBean
#ViewScoped
public class BeanPersona implements Serializable {
private Persona persona = new Persona();
private Persona currPersona = new Persona();
public BeanPersona() {
persona = new Persona();
currPersona = new Persona();
}
public Persona getCurrPersona() {
return currPersona;
}
public void setCurrPersona(Persona currPersona) {
this.currPersona = currPersona;
}
public Persona getPersona() {
return persona;
}
public void setPersona(Persona persona) {
this.persona = persona;
}
public void eliminar(Persona currPersona) {
if(currPersona != null) {
new Dml().delete(currPersona, currPersona.getId());
listar();
System.out.println("succefull delete !!!!");
} else if(this.currPersona != null){
new Dml().delete(this.currPersona, this.currPersona.getId());
this.currPersona = new Persona();
listar();
System.out.println("succefull delete this.currPersona!!!!");
} else {
System.out.println("currPersona is null !!!!");
}
}
public String nullMethod () {return null;}
}
currPersona still null when I throw the method
The attribute onclick is for client side behaviour like executing some JS or showing up a dialog etc. You are not defining an actionListener for your commandButton at all.
Try to remove the onclick completely and use a proper actionListener instead:
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash"
update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();"
actionListener="#{beanPersona.someActionListener}">
<f:setPropertyActionListener value="#{per}"
target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
I solved it, I just put process tag into "confirm" commandButton with value at "#this"
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.setCurrPersona(per)}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar a paciente Nº #{beanPersona.currPersona.id} ?" closeOnEscape="true" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar}" process="#this"/>
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>

The event filter does not update the entire table

I'm using the event filter to recalculate the totals of the some columns, when filter run new values is calculate ok in the backingBean but not updated in the table. The values is sumaTotal, sumaCUP and sumaCUC and appear at footer of each column.
this is the code:
<p:dataTable emptyMessage="No se encontraron elementos" widgetVar="tb1"
id="tablaFact" var="item" selection="#{listadoFacturasMB.selectedFactura}" selectionMode="single" paginator="true"
rows="20" rowKey="#{item.idFactura}" value="#{listadoFacturasMB.facturaUtilList}" filteredValue="#{listadoFacturasMB.filterFacturaUtilList}">
<p:ajax event="rowSelect" update=":frm1:growl :frm1:panelDetallesServicio" oncomplete="servDialog.show()" listener="#{listadoFacturasMB.createPDF}"/>
<p:ajax event="rowUnselect" update=":frm1:growl"/>
<p:ajax event="filter" listener="#{listadoFacturasMB.filterListener(filterEvent)}" update="tablaFact"/>
<f:facet name="header">
<h:outputText value="Listado de facturas"/>
<p:commandButton id="downloadLink" value="Recargar" icon="ui-icon-refresh" oncomplete="tb1.clearFilters()" update="tablaFact" actionListener="#{listadoFacturasMB.cargarFacturas}"/>
</f:facet>
<p:column style="width:10%" sortBy="#{item.noFactura}" filterBy="#{item.noFactura}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nro"/>
</f:facet>
<h:outputText value="#{item.noFactura}"/>
</p:column>
<p:column style="width:10%" sortBy="#{item.idClientefk}" filterBy="#{item.idClientefk}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Cliente"/>
</f:facet>
<h:outputText value="#{item.idClientefk}"/>
</p:column>
<p:column style="width:10%" sortBy="#{item.idPropietariofk.area}" filterBy="#{item.idPropietariofk.area}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="UEB"/>
</f:facet>
<h:outputText value="#{item.idPropietariofk.area}"/>
</p:column>
<p:column style="width:10%" id="cff3">
<f:facet name="header">
<h:outputText value='Importe Total'/>
</f:facet>
<h:outputText value="#{item.importeTotal}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaTotal}"/>
</f:facet>
</p:column>
<p:column style="width:10%" id="cdd3">
<f:facet name="header">
<h:outputText value='Importe CUP'/>
</f:facet>
<h:outputText value="#{item.importeCup}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaCUP}"/>
</f:facet>
</p:column>
<p:column style="width:10%" id="cjj3">
<f:facet name="header">
<h:outputText value='Importe CUC'/>
</f:facet>
<h:outputText value="#{item.importeCuc}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaCUC}"/>
</f:facet>
</p:column>
</p:dataTable>
backing bean:
public void filterListener(FilterEvent filterEvent) {
try {
sumaTotal = new BigDecimal(0);
sumaCUP = new BigDecimal(0);
sumaCUC = new BigDecimal(0);
for (int i = 0; i < filterFacturaUtilList.size(); i++) {
FacturaUtil facturaUtil = filterFacturaUtilList.get(i);
this.sumaTotal = this.sumaTotal.add(facturaUtil.getImporteTotal());
this.sumaCUP = this.sumaCUP.add(facturaUtil.getImporteCup());
this.sumaCUC = this.sumaCUC.add(facturaUtil.getImporteCuc());
}
this.sumaTotal = this.sumaTotal.setScale(2, RoundingMode.HALF_UP);
this.sumaCUP = this.sumaCUP.setScale(2, RoundingMode.HALF_UP);
this.sumaCUC = this.sumaCUC.setScale(2, RoundingMode.HALF_UP);
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: filterListener() " + e.getMessage());
}
}

Backing bean method is getting null from inputs

This project is made with Primefaces 3.5, JSF 2.0, Oracle database.
The view:
<h:form id="schedule" class="schedule">
// more JSF and forms and dialogs
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
// more JSF and dialogshizzle
</h:form>
The backing bean:
#ManagedBean(name="waitinglistBean")
#ViewScoped
public class WaitinglistBean implements Serializable
{
private Patients patient;
private OrWaitinglist orWaitinglist;
private List<Patients> patients = new ArrayList<Patients>();
private String name;
private Integer pcode;
public WaitinglistBean() {
}
public void setSelectedPatient(Patients patient) {
this.patient = patient;
}
public Patients getSelectedPatient() {
return patient;
}
public OrWaitinglist getOrWaitinglist() {
return orWaitinglist;
}
public void setOrWaitinglist(OrWaitinglist orWaitinglist) {
this.orWaitinglist = orWaitinglist;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPcode() {
return pcode;
}
public void setPcode(Integer pcode) {
this.pcode = pcode;
}
public List<Patients> getPatients() {
PatientsDao patientsDao = new PatientsDaoImpl();
patients = patientsDao.getSearchPatient(name, pcode);
System.out.println(name + " " + pcode);
return patients;
}
public void createOrWaitinglist()
{
orWaitinglist.setPatients(patient);
}
So first a user enter a string: "Firstname" and an Integer: "Patient Code".
When he hits the "Search" button it fires the actionListener="#{patientBean.patients}
inside that commandbutton. The method needs 2 parameter, name and pcode which have their own setters/getters.
When I look in console it shows me the printout of these 2 parameters, and they are twice "null", so that means the parameters from the JSF pages were not passed to the backing bean, although the value of the inputText has been set to the backingbean set method: value="#{patientBean.name}"
My question now is why do I get these null-values. I've read several posts which use these setters, but still I get null-values.
after edit i still have the same problem;
for send value of input component in h:panelgrid to the backingbean use somthing like this:
<p:commandButton value="Search" process="#(frmPatient:findPatientParameters :input)"
actionListener="#{patientBean.patients}" update="patients"/>

primefaces commandbutton actionlistener not called

I am using primefaces 3.0 and jsf 2.0.
I have prepared client master which add client using wizard and at the same time reflected in datatable. Then I have updated edit utility in datatable. Then I have added delete button in datatable and try call delete method of bean.
But when I click on delete button wizard validation for adding client is executed.
So I have created another file ClientEditdatatable.xhtml and included in clientmaster.xhtmlbut same result remain.
Now I want to add delete utility in datatable. I have tried many tricks to do it.
I just want to pass client id through action listener,get deleted and refresh datatable but command button not executing method.
Kindly advice.
My code as below:
ClientMaster.xhtml
<h:body>
<ui:composition template="/template/mainLayout.xhtml" >
<ui:define name="pageContent">
<h:form id="cm">
<p:growl life="5000" showDetail="true" showSummary="true" id="mymessage" autoUpdate="true"/>
<br/>
user id :#{sessionScope.USER_ID};
<br/>
<p:wizard widgetVar="wiz" flowListener="#{clientUitility.onFlowProcess}" showNavBar="true" >
<p:tab id="personal" title="Personal" >
<p:panel id="personal1" header="Personal Details">
<!-- <h:messages errorClass="error"/> -->
<h:panelGrid columns="6" styleClass="grid">
<h:outputText value="First Name:*" />
<p:inputText required="true" label="FirstName"
value="#{clientUitility.client.firstName}" >
</p:inputText>
<h:outputText value="Middle Name:*" />
<p:inputText required="true" label="MidddleName"
value="#{clientUitility.client.middleName}" />
<h:outputText value="Last Name:*" />
<p:inputText required="true" label="LastName"
value="#{clientUitility.client.lastName}" />
<h:outputText value="Login ID:* " />
<p:inputText required="true" label="LoginID"
value="#{clientUitility.client.loginID}"/>
<h:outputText value="Password:* " />
<p:inputText required="true" label="Password"
value="#{clientUitility.client.password}"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="address" title="Address" >
<p:panel id="address1" header="Adress Details">
<!-- <h:messages errorClass="error"/> -->
<h:panelGrid columns="6" styleClass="grid">
<h:outputText value="Address:*" />
<p:inputText required="true" label="Address1"
value="#{clientUitility.client.address1}" />
<h:outputText />
<p:inputText label="Address2"
value="#{clientUitility.client.address2}" />
<h:outputText />
<p:inputText label="Address3"
value="#{clientUitility.client.address3}" />
<h:outputText value="City:* " />
<p:inputText required="true" label="City"
value="#{clientUitility.client.city}" />
<h:outputText value="Pincode:* " />
<p:inputText required="true" label="Pincode"
value="#{clientUitility.client.pincode}" />
<h:outputText value="State:* " />
<p:inputText required="true" label="State"
value="#{clientUitility.client.state}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="contact" title="Contact" >
<p:panel id="contact1" header="Contact Information">
<!-- <h:messages errorClass="error"/> -->
<p:panelGrid columns="4" styleClass="grid">
<h:outputText value="Mobile:* " />
<p:inputText required="true" label="MobileNo"
value="#{clientUitility.client.mobileNo}" />
<h:outputText value="Email ID: "/>
<p:inputText label="EmailID"
value="#{clientUitility.client.emailID}" />
<h:outputText value="STD Code: "/>
<p:inputText label="STDCode"
value="#{clientUitility.client.stdCode}" />
<h:outputText value="Phone No: "/>
<p:inputText label="PhoneNo"
value="#{clientUitility.client.phoneNo}" /> </p:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation" >
<p:panel id="confirm1" header="Confirm and Submit">
<h:panelGrid columns="6" styleClass="grid" >
<h:outputText value="First Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.firstName}" />
<h:outputText value="Middle Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.middleName}" />
<h:outputText value="Last Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.lastName}" />
<h:outputText value="Login ID: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.loginID}"/>
<h:outputText value="Password: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.password}"/>
<h:outputText/>
<h:outputText/>
<h:outputText value="Address: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address1}" />
<h:outputText />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address2}" />
<h:outputText />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address3}" />
<h:outputText value="City: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.city}" />
<h:outputText value="State: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.state}" />
<h:outputText value="Pincode: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.pincode}" />
<h:outputText value="Email ID: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.emailID}" />
<p:commandButton id="addClient" immediate="true" value="Add Client" actionListener="#{clientUitility.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)" update="#parent,:cm:clientList"> <!-- update="#parent,:cm:clientList" -->
</p:commandButton>
</h:panelGrid>
</p:panel>
</p:tab>
</p:wizard>
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
ClientEditDatatable.xhtml
<h:body>
<h:form id="fce">
<p:confirmDialog message="Delete client?" severity="alert" widgetVar="confirmDeleteClient" visible="false" appendToBody="true">
<p:commandButton value="Yes" update=":cm:fce:clientList" oncomplete="confirmDeleteClient.hide()" actionListener="#{clientUitility.deleteRecord}" >
</p:commandButton>
<p:commandButton value="No" onclick="confirmDeleteClient.hide()" type="button" />
</p:confirmDialog>
<p:dataTable var="client" value="#{clientUitility.clientAll}" id="clientList" editable="true"
rowKey="#{client.clientID}" paginator="true" rows="10" rowsPerPageTemplate="10,15,20">
<p:column headerText="First Name" style="width:125px" filterBy="#{user.firstname}" sortBy="#{client.firstName}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.firstName}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{client.firstName}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Middle Name" style="width:125px" filterBy="#{client.middleName}" sortBy="#{client.middleName}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.middleName}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.middleName}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Last Name" style="width:125px" filterBy="#{client.lastName}" sortBy="#{client.lastName}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.lastName}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.lastName}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Login ID" style="width:125px" filterBy="#{client.loginID}" sortBy="#{client.loginID}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.loginID}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.loginID}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Password" style="width:125px" filterBy="#{client.password}" sortBy="#{client.password}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.password}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.password}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address1" style="width:125px" filterBy="#{client.address1}" sortBy="#{client.address1}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address1}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address1}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address2" style="width:125px" filterBy="#{client.address2}" sortBy="#{client.address2}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address2}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address2}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address3" style="width:125px" filterBy="#{client.address3}" sortBy="#{client.address3}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address3}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address3}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="City" style="width:125px" filterBy="#{client.city}" sortBy="#{client.city}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.city}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.city}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State" style="width:125px" filterBy="#{client.state}" sortBy="#{client.state}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.state}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.state}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Pincode" style="width:125px" filterBy="#{client.pincode}" sortBy="#{client.pincode}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.pincode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.pincode}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Mobile No" style="width:125px" filterBy="#{client.mobileNo}" sortBy="#{client.mobileNo}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.mobileNo}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.mobileNo}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="STD Code" style="width:125px" filterBy="#{client.stdCode}" sortBy="#{client.stdCode}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.stdCode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.stdCode}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Phone No" style="width:125px" filterBy="#{client.phoneNo}" sortBy="#{client.phoneNo}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.phoneNo}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.phoneNo}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email ID" style="width:125px" filterBy="#{client.emailID}" sortBy="#{client.emailID}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.emailID}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.emailID}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{clientUitility.editRowListner}" update=":cm:mymessage"/>
<p:column headerText="Delete" style="width:50px">
<p:commandButton id="deleteClient" value="Delete" onclick="confirmDeleteClient.show()" title="Delete this Client" styleClass="ui-icon-closethick">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
</h:body>
clientUtility.java
#ManagedBean
#ViewScoped
public class ClientUitility {
private ClientBean client = new ClientBean();
private List<ClientBean> clientAll = new ArrayList<ClientBean>();
/** Creates a new instance of ClientUitility */
public ClientUitility() {
clientAll = new ArrayList<ClientBean>();
int userID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
clientAll = ClientService.GenerateClientList(userID);
}
public List<ClientBean> getClientAll() {
return clientAll;
}
public void setClientAll(List<ClientBean> clientAll) {
this.clientAll = clientAll;
}
public ClientBean getClient() {
return client;
}
public void setClient(ClientBean client) {
this.client = client;
}
public String onFlowProcess(FlowEvent event) {
System.out.println("Current wizard step:" + event.getOldStep());
System.out.println("Next step:" + event.getNewStep());
System.out.println("First name : " + client.getfirstName());
System.out.println("Last name : " + client.getlastName());
System.out.println("Age name : " + client.getloginID());
return event.getNewStep();
}
public void editRowListner(RowEditEvent rowEditEvent) {
try {
ClientBean updatedClient = (ClientBean) rowEditEvent.getObject();
System.out.println("Client First Name: " + updatedClient.getfirstName());
ClientService.EditClient(updatedClient);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Updated", updatedClient.getfirstName() + " " + updatedClient.getlastName()));
} catch (Exception e) {
e.getMessage();
}
}
public void deleteRecord(ActionEvent actionEvent) {
try {
//System.out.println("Client ID: " + actionEvent.getComponent().getAttributes().get("cID").toString());
System.out.println("delete client of User ID: " + FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
FacesMessage msg = new FacesMessage("Client Deleted", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
}
}
public void save(ActionEvent actionEvent) { client.setuserID(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
System.out.println("Client ID : " + client.getclientID());
System.out.println("User ID : " + client.getuserID());
ClientService.AddClient(client);
client = new ClientBean();
clientAll = ClientService.GenerateClientList(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
FacesMessage msg = new FacesMessage("Client Created", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
Kindly advice where am I mistaking?
You can't and shouldn't nest forms.
In the ClientMaster.xhtml, replace
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
</h:form>
by
</h:form>
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Resources