I have a problem with primefaces datatable which implements filtering and sorting and select rows (like complex datatable in primefaces showcases), when I sort or filter in datatable, SelectedElement resolve to null if I select a row, but if I choose a row without filtering or sorting, select event work perfectly.
My xhtml.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Liste des Prospects</title>
<style type="text/css">
</style>
</h:head>
<h:body>
<p:layout style="min-width:900px;min-height:400px;" id="layout" fullPage="true">
<p:layoutUnit size="50" position="north" ><ui:include src="/Menus.xhtml" /></p:layoutUnit>
<h:form id="form">
<p:layoutUnit position="center" size="230" resizable="false" closable="true" collapsible="true">
<p:layout>
<p:layoutUnit position="center">
<p:dataTable id="cars" scrollable="true" frozenColumns="4"
selection="#{prospectBean.selectedProspect}" selectionMode="single" stickyHeader="false" var="listd"
sortMode="single" widgetVar="ProspectTable" value="#{prospectBean.list}" rowKey="#{listd.idProspect}"
emptyMessage="Pas de prospects avec ces critères" rowSelectMode="single" filteredValue="#{prospectBean.filteredProspects}">
<p:ajax event="rowSelect" listener="#{prospectBean.onRowSelect}" update=":form:Agenda" />
<p:ajax event="rowUnselect" listener="#{prospectBean.onRowUnSelect()}"/>
<p:ajax event="filter" update=":form:cars" />
<f:facet name="header" >
<p:outputPanel >
<h:outputText style="width:150px;" value="Chercher dans tous les camps:" />
<p:inputText id="globalFilter" onkeyup="PF('ProspectTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
<p:commandButton action="#{prospectBean.AjouterProspect()}" style="width:12%;float: left;height:8%" ajax="false" icon="ui-icon-circle-plus" />
</p:outputPanel>
</f:facet>
<p:column width="14" >
<p:commandButton action="#{prospectBean.ModifierProspect(listd)}" style="width:15px;height:15px" ajax="false" icon="ui-icon-pencil"/>
</p:column>
<p:column width="140" sortBy="#{listd.raisonsociale}" headerText="Raison Sociale" filterBy="#{listd.raisonsociale}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.raisonsociale}"/>
</p:column>
<p:column width="140" sortBy="#{listd.raisonsocialeabrg}" headerText="RS Abrégé" filterBy="#{listd.raisonsocialeabrg}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.raisonsocialeabrg}"/>
</p:column>
<p:column width="140" sortBy="#{listd.telephone}" headerText="Téléphone" filterBy="#{listd.telephone}" filterStyle="display:none">
<h:outputText value="#{listd.telephone}"/>
</p:column>
<p:column width="140" sortBy="#{listd.telephone2}" headerText="Téléphone 2" filterBy="#{listd.telephone2}" filterStyle="display:none">
<h:outputText value="#{listd.telephone2}"/>
</p:column>
<p:column width="140" sortBy="#{listd.fax}" headerText="Fax" filterBy="#{listd.fax}" filterStyle="display:none">
<h:outputText value="#{listd.fax}"/>
</p:column>
<p:column width="190" sortBy="#{listd.siteWeb}" headerText="Site Web" filterBy="#{listd.siteWeb}" filterStyle="display:none">
<h:outputText value="#{listd.siteWeb}"/>
</p:column>
<p:column width="190" sortBy="#{listd.email}" headerText="Email" filterBy="#{listd.email}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.email}"/>
</p:column>
<p:column width="140" sortBy="#{listd.ville}" headerText="Ville" filterBy="#{listd.ville}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.ville}"/>
</p:column>
<p:column width="140" sortBy="#{listd.pays}" headerText="Pays" filterBy="#{listd.pays}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText value="#{listd.pays}"/>
</p:column>
<p:column width="140" sortBy="#{listd.chiffreaffaire}" headerText="Chiffre d'affaire" filterBy="#{listd.chiffreaffaire}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.chiffreaffaire}"/>
</p:column>
<p:column width="140" sortBy="#{listd.activite}" headerText="Activite" filterBy="#{listd.activite}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.activite}"/>
</p:column>
<p:column width="140" sortBy="#{listd.secteur}" headerText="Secteur" filterBy="#{listd.secteur}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.secteur}"/>
</p:column>
<p:column width="140" sortBy="#{listd.statut.denomination}" headerText="Statut" filterBy="#{listd.statut.denomination}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.statut.denomination}"/>
</p:column>
</p:dataTable>
</p:layoutUnit>
<p:layoutUnit position="south" size="322" resizable="false" closable="true" collapsible="true">
<p:dataTable id="Agenda" scrollable="false" filteredValue="#{AgendaBean.filteredAgenda}"
selectionMode="single" var="lista" sortMode="single"
widgetVar="AgendaTable" value="#{AgendaBean.list}" rowKey="#{lista.id}"
emptyMessage="Pas d'événement avec ces critères" >
<f:facet name="header" >
<p:outputPanel >
<h:outputText style="width:150px;" value="Chercher dans tous les camps:" />
<p:inputText id="globalFilter" onkeyup="PF('AgendaTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
<p:commandButton action="#{AgendaBean.AjouterAgenda()}" rendered="#{prospectBean.checked}" style="width:12%;height:6%;float: left;" ajax="false" icon="ui-icon-circle-plus" />
</p:outputPanel>
</f:facet>
<p:column width="17" >
<p:commandButton action="#{AgendaBean.ModifierAgenda(lista)}" style="width:15px; height:17px" ajax="false" icon="ui-icon-pencil"/>
</p:column>
<p:column sortBy="#{lista.dateHeure}" width="170" headerText="Date Heure" filterBy="#{lista.dateHeure}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id01" value="#{lista.dateHeure}"/>
</p:column>
<p:column sortBy="#{lista.natureevenement.libelle}" headerText="Nature" filterBy="#{lista.natureevenement.libelle}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id11" value="#{lista.natureevenement.libelle}"/>
</p:column>
<p:column sortBy="#{lista.intervenant.nom}" headerText="Intervenant" filterBy="#{lista.intervenant.nom}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id21" value="#{lista.intervenant.nom}"/>
</p:column>
<p:column sortBy="#{lista.statut.denomination}" headerText="Statut" filterBy="#{lista.statut.denomination}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id31" value="#{lista.statut.denomination}"/>
</p:column>
<p:column sortBy="#{lista.duree}" width="70" headerText="Duree" filterBy="#{lista.duree}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id41" value="#{lista.duree}"/>
</p:column>
<p:column sortBy="#{lista.lieu}" width="170" headerText="Lieu" filterBy="# {lista.lieu}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id61" value="#{lista.lieu}"/>
</p:column>
</p:dataTable>
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
</h:form>
</p:layout>
</h:body>
</html>
MyBean
#ManagedBean(name="prospectBean")
#SessionScoped
public class ProspectBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
....
public void onRowSelect(SelectEvent se)
{
setProspect(getSelectedProspect());
agendabean.setProspect(getSelectedProspect());
checked=true;
try{
AgendaBean.AfficherAgendas(getProspect());
}catch(Exception e){e.printStackTrace();}
System.out.print("ca marche encore");
}
public void onRowUnSelect(SelectEvent se)
{
checked=false;
}
//agendabean.setProspect(getSelectedProspect()); resolve to null pointer exception
java.lang.NullPointerException
at Interface.AgendaBean.AfficherAgendas(AgendaBean.java:508)
at Interface.ProspectBean.onRowSelect(ProspectBean.java:775)
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.
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
I hope somebody could help me with the trouble I am having with JSF 2 and Primefaces 3.0M3.
the problem is that the back bean methods do not fired from any component in the layoutunit 'center' they are inside a form and nothing happens, even I tried to update the components with remoteCommand, autoUpdate of the outputpanel, commandButton with action and actionListener and nothing, there is no error message. In the layoutunit west works the components well, renders the outputpanel (pfpInfo) of the center layoutunit but I do not know what is happening.
here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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.prime.com.tr/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Articulos</title>
</h:head>
<h:body>
<link rel="stylesheet" type="text/css" href="../css/estilos.css" />
<p:layout fullPage="true" id="lay">
<p:layoutUnit position="north" size="100" resizable="false"
closable="false" collapsible="false">
<img src="../images/logo.jpg" alt="PLL"
style="width: 413px; height: 83px;" align="left"></img>ss
<img src="../images/tel.jpg" alt="PLR"
style="width: 413px; height: 83px;" align="right"></img>
</p:layoutUnit>
<p:layoutUnit position="west" size="200" header="Categorías"
resizable="false" closable="false" collapsible="false">
<h:form id="frWest">
<p:growl id="message" showDetail="true" globalOnly="true"
autoUpdate="true"></p:growl>
<p:tree id="treeSingle" value="#{controlMBean.raizArbol}"
var="rama" dynamic="true" selectionMode="single"
selection="#{controlMBean.ramaElegida}" expanded="true">
<p:ajax event="select"
update=":frCenter:pfSeg :frCenter:pfpInfo :frCenter:pfpIma"
listener="#{controlMBean.procesaInformacionArt}"></p:ajax>
<p:treeNode>
<h:outputText value="#{rama}" styleClass="encabezadoUiLight" />
</p:treeNode>
</p:tree>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:form id="frCenter">
<p:outputPanel id="pfSeg" rendered="true">
<p:outputPanel id="pfpIma" rendered="#{not controlMBean.cargado}">
<img src="../images/luchadores.jpg" />
</p:outputPanel>
<p:outputPanel id="pfpInfo" rendered="#{controlMBean.cargado}"
autoUpdate="true">
<p:dataTable dynamic="true" var="prnda" rowKey="#{prnda.id}"
value="#{controlMBean.infoArts}" paginator="true" rows="10"
selectionMode="single" paginatorAlwaysVisible="false"
selection="#{controlMBean.artElegido}"
rendered="#{controlMBean.cargado}">
<p:ajax event="rowUnselect"
listener="#{prestalana.deseleccionar}"></p:ajax>
<f:facet name="header">Articulo(s)</f:facet>
<p:ajax update=":frCenter:ppImg :frCenter:pgInfo"
oncomplete="prnd.show()" event="rowSelect"
listener="#{controlMBean.elegirFila}"></p:ajax>
<p:column sortBy="#{prnda.id}">
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{prnda.id}" />
</p:column>
<p:column sortBy="#{prnda.articulo}">
<f:facet name="header">
<h:outputText value="Modelo" />
</f:facet>
<h:outputText value="#{prnda.articulo}" />
</p:column>
<p:column sortBy="#{prnda.marca}">
<f:facet name="header">
<h:outputText value="Marca" />
</f:facet>
<h:outputText value="#{prnda.marca}" />
</p:column>
<p:column sortBy="#{prnda.edo}">
<f:facet name="header">
<h:outputText value="Ubicación" />
</f:facet>
<h:outputText value="#{prnda.edo}" />
</p:column>
<p:column sortBy="#{prnda.stsArticulo}">
<f:facet name="header">
<h:outputText value="Estatus" />
</f:facet>
<h:outputText value="#{prnda.stsArticulo} " />
</p:column>
<p:column sortBy="#{prnda.precio}">
<f:facet name="header">
<h:outputText value="Precio" />
</f:facet>
<h:outputText value="$ #{prnda.precio}" />
</p:column>
</p:dataTable>
<p:commandButton action="#{controlMBean.probar2}"
actionListener="#{controlMBean.probar}" value="Prueba"></p:commandButton>
</p:outputPanel>
<br />
<h:outputText value="#{controlMBean.mensaje}"
styleClass="textoUiLight" id="hotMen" />
</p:outputPanel>
<p:remoteCommand actionListener="#{controlMBean.probar}"
name="pruebaRc" update=":frCenter:ppImg"></p:remoteCommand>
<p:dialog appendToBody="true" dynamic="true" header="Info Prenda"
onShow="pruebaRc" widgetVar="prnd" resizable="false" width="750"
height="550" showEffect="fold" position="center"
hideEffect="explode">
<p:outputPanel id="ppImg" autoUpdate="true">
<h:panelGrid columns="2" id="pgInfo">
<p:galleria transitionInterval="3000" var="i"
value="#{controlMBean.imagenes}"
panelWidth="#{controlMBean.width}"
panelHeight="#{controlMBean.height}"
frameHeight="#{controlMBean.height/4}"
frameWidth="#{controlMBean.width/4}" effect="flash">
<p:graphicImage id="img" height="#{i.alto}" width="#{i.ancho}"
value="#{controlMBean.ruta}#{i.nombre}.jpg" />
</p:galleria>
<h:panelGrid columns="2" width="350">
<h:outputLabel value="ID:" styleClass="etiqueta" />
<h:outputText value="#{controlMBean.artElegido.id}"
styleClass="resultado" />
<h:outputLabel value="Prenda:" styleClass="etiqueta" />
<h:outputText
value="#{controlMBean.artElegido.prenda} adasd"
styleClass="resultado" />
<h:outputLabel value="Precio:" styleClass="etiqueta" />
<h:outputText value="$#{controlMBean.artElegido.precio}"
styleClass="resultado" />
<h:outputLabel value="Marca:" styleClass="etiqueta" />
<h:outputText value="#{controlMBean.artElegido.marca}"
styleClass="resultado" />
<h:outputLabel value="Sucursal:" styleClass="etiqueta" />
<h:outputText value="#{controlMBean.artElegido.suc}"
styleClass="resultado" />
<h:outputLabel value="Descripcion:" styleClass="etiqueta" />
<h:outputText value="#{controlMBean.artElegido.descr}"
styleClass="resultado" style="width:300px;height:100px;" />
</h:panelGrid>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</p:layoutUnit>
</p:layout>
</h:body>
</html>
I have datatable and a dropdown within a xhtml. If I am deleting p:datatable code within this page then I am able to call the valueChangeListener of dropdown , but if p:datatable is present in xhtml, then I am not able to call it.
Xhtml code is
<ui:define name="content">
<f:view>
<h:form id="accountSummaryForm" prependId="false">
<h:selectBooleanCheckbox id="checkbox" value="true" />
<h:outputLabel value="Show certificates preview on sumit"></h:outputLabel>
<h:outputLabel value="Show certificates preview on sumit"></h:outputLabel>
<h:outputText align="left"
value="Value is #{reqSummaryHandler.certNumber}" />
<p:dataTable id="reqActList" paginatorAlwaysVisible="true"
var="reqInfo" value="#{reqSummaryHandler.certActListModel}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true" rows="#{label.accountList_defaultNumberOfRows}"
selectionMode="single"
rowsPerPageTemplate="#{label.accountList_numberOfRows}" width="60%">
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="#{label.certNumber}" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.certNumber}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Version" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.certVersionNbrString}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Insured" />
</f:facet>
<ui:repeat value="#{reqInfo.clientList}" var="insuredInfo">
<h:outputText align="left"
value="#{insuredInfo.generalPartyInfo.nameInfo.commName.commercialName}" />
</ui:repeat>
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Certificate Holder" />
</f:facet>
<ui:repeat value="#{reqInfo.certificateHolderInfoList}"
var="certHoldInfo">
<h:outputText align="left"
value="#{certHoldInfo.additionalInterest.generalPartyInfo.nameInfo.commName.commercialName}" />
</ui:repeat>
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Activity Performed" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.effectiveTypeCd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Certificate Status" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.statusCd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Third Party" />
</f:facet>
<h:outputText align="left"
value="#{reqInfo.certWordingEndorsementInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Manual Form" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.manualEntryInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Manual Addendum" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.mnlAddendumInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Path" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText align="left" value="#{reqInfo.routePathCd}"
readonly="true" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{reqInfo.routePathCd}">
<f:selectItem itemLabel="Issue Distribute" itemValue="A" />
<f:selectItem itemLabel="Send to Underwriter" itemValue="B" />
<f:selectItem itemLabel="Issue Do Not Distribute"
itemValue="C" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
<p:rowEditor rendered="#{reqInfo.statusCd eq 'A'}" />
</p:column>
<p:column style="text-align:center;white-space: normal;nowrap">
<f:facet name="header">
<h:outputLabel value="Action" />
</f:facet>
<ui:repeat value="#{reqInfo.availableFunctions.functionNameArray}"
var="linkInfo">
<p:commandLink id="View" value="#{linkInfo}" ajax="false" />
<br />
</ui:repeat>
</p:column>
</p:dataTable>
<p:spacer width="50" height="0"></p:spacer>
<p:spacer width="50" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<h:outputLabel value="Assign Path" style="font-weight:bold" />
<p:spacer width="5" height="10" />
<h:selectOneMenu id="dropdown2"
valueChangeListener="#{reqSummaryHandler.DoPathProcessing1}"
value="#{reqSummaryHandler.certNumber}" onchange="submit();">
<f:selectItem itemLabel="Issue Distribute" itemValue="A" />
<f:selectItem itemLabel="Send to Underwriter" itemValue="B" />
<f:selectItem itemLabel="Issue Do Not Distribute" itemValue="C" />
</h:selectOneMenu>
</h:form>
</f:view>
</ui:define>
And listener code is
public void DoPathProcessing1(ValueChangeEvent event) {
String newValue = (String) event.getNewValue();
System.out.println("Path"
+ certActListModel.getRowData().getRoutePathCd());
certActListModel.getRowData().setRoutePathCd(newValue);
System.out.println("value is " + newValue);
}
Any idea why it is not working?
I am using jsf-api-2.0.3 and primefaces-2.2.1
You are using both the value and the valueChangeListener attributes of the drop down component. Why would you do this?
Just having value="#{reqSummaryHandler.certNumber} will call setCertNumber(String certNumber) in your managed bean. Why not just put this code into the setter method?