i'm using jsf 2.2 primefaces 6.0 and i'm trying to update and delete users from table using "rowkey".When i click on the table a Dialog appears with the values of the row in order to update and delete the row column.After that i used another button to consult another datatable which are assures of the users.When i try to repeat the same thing by try editing the assure table using row key and Dialog, it enables me to update and delete the values of the row but it disable the possiblity to update and delete the previous table which is users table.
In order to enable the modification of the user table again i need to disable the row key option from the assures table.
The java Bean code:
package mBeans;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.FlowEvent;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import org.primefaces.model.chart.PieChartModel;
import persistence.Administrateur;
import persistence.Assure;
import persistence.Employer;
import persistence.User;
import services.UserServicesLocal;
@ManagedBean
@ViewScoped
public class UtilisateurBean {
private List<Employer> employersToList = new ArrayList<>();
private List<Administrateur> administrateursToList = new ArrayList<>();
private List<Assure> assuresByEmployee = new ArrayList<>();
private List<Assure> assuresByAdmin = new ArrayList<>();
private List<User> users = new ArrayList<>();
private List<User> usersFiltred = new ArrayList<>();
private Employer employer = new Employer();
private Employer employerSelected = new Employer();
private Administrateur administrateur = new Administrateur();
private Administrateur administrateurSelected = new Administrateur();
private Assure assureSelected = new Assure();
public Assure getAssureSelected() {
return assureSelected;
}
public void setAssureSelected(Assure assureSelected) {
this.assureSelected = assureSelected;
}
private String matricule = "";
private String mail = "";
private String nom = "";
private String login = "";
private String password = "";
private String prenom = "";
private String type = "";
private List<Assure> assures = new ArrayList<>();
private List<Assure> assuresToAdd = new ArrayList<>();
private Assure assure = new Assure();
@ManagedProperty(value = "#{identity}")
private Identity identity;
@EJB
private UserServicesLocal userServicesLocal;
private boolean skip;
private PieChartModel pieModel1;
int nbUsers;
int nbAdmins;
@PostConstruct
public void init() {
createPieModelS();
}
private void createPieModelS() {
pieModel1 = new PieChartModel();
nbAdmins = userServicesLocal.findAllAdmins().size();
nbUsers = userServicesLocal.findAllEmployers().size();
pieModel1.set("Utilisateurs", nbUsers);
pieModel1.set("Administrateurs", nbAdmins);
pieModel1.setFill(false);
pieModel1.setShowDataLabels(true);
pieModel1.setDiameter(150);
pieModel1.setTitle("Statistiques utilisateurs");
pieModel1.setLegendPosition("w");
}
public String onFlowProcess(FlowEvent event) {
if (skip) {
skip = false; // reset in case user goes back
return "confirm";
} else {
return event.getNewStep();
}
}
public void deleteAssureFromListToAdd(Assure assure) {
assuresToAdd.remove(assure);
}
public String doAddUtilisateur() {
if (type.equals("Collaborateur")) {
Employer employer = new Employer(nom, prenom, matricule, password, mail);
employer.linkAssures(assuresToAdd);
userServicesLocal.saveOrUpdateUser(employer);
} else {
Administrateur administrateur = new Administrateur(nom, prenom, matricule, password, mail);
administrateur.linkAssures(assuresToAdd);
userServicesLocal.saveOrUpdateUser(administrateur);
}
setSkip(false);
return "/pages/listUsers?faces-redirect=true";
}
public void addToListAssures() {
assuresToAdd.add(assure);
assure = new Assure();
}
public void updateAssure() {
userServicesLocal.saveOrUpdateUser(assure);
}
public void deleteAssure() {
userServicesLocal.deleteUser(assure);
}
public void updateUtilisateur() {
userServicesLocal.saveOrUpdateUser(employerSelected);
}
public void updateAdministrateur() {
userServicesLocal.saveOrUpdateUser(administrateurSelected);
}
public void suprimerUtilisateur() {
userServicesLocal.deleteUser(employerSelected);
}
public void suprimerAdministrateur() {
userServicesLocal.deleteUser(administrateurSelected);
}
public void cancel() {
}
public Employer getEmployer() {
return employer;
}
public void setEmployer(Employer employer) {
this.employer = employer;
}
public String getMatricule() {
return matricule;
}
public void setMatricule(String matricule) {
this.matricule = matricule;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<Assure> getAssures() {
assures = userServicesLocal.findAssuresParEmployer((Employer) identity.getUser());
return assures;
}
public void setAssures(List<Assure> assures) {
this.assures = assures;
}
public Identity getIdentity() {
return identity;
}
public void setIdentity(Identity identity) {
this.identity = identity;
}
public Assure getAssure() {
return assure;
}
public void setAssure(Assure assure) {
this.assure = assure;
}
public List<Assure> getAssuresToAdd() {
return assuresToAdd;
}
public void setAssuresToAdd(List<Assure> assuresToAdd) {
this.assuresToAdd = assuresToAdd;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public UserServicesLocal getUserServicesLocal() {
return userServicesLocal;
}
public void setUserServicesLocal(UserServicesLocal userServicesLocal) {
this.userServicesLocal = userServicesLocal;
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public List<User> getUsers() {
users = userServicesLocal.findAllUsers();
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public List<User> getUsersFiltred() {
return usersFiltred;
}
public void setUsersFiltred(List<User> usersFiltred) {
this.usersFiltred = usersFiltred;
}
public List<Employer> getEmployersToList() {
employersToList = userServicesLocal.findAllEmployers();
return employersToList;
}
public void setEmployersToList(List<Employer> employersToList) {
this.employersToList = employersToList;
}
public List<Administrateur> getAdministrateursToList() {
administrateursToList = userServicesLocal.findAllAdmins();
return administrateursToList;
}
public void setAdministrateursToList(List<Administrateur> administrateursToList) {
this.administrateursToList = administrateursToList;
}
public List<Assure> getAssuresByEmployee() {
assuresByEmployee = userServicesLocal.findAssuresParEmployer(employerSelected);
return assuresByEmployee;
}
public void setAssuresByEmployee(List<Assure> assuresByEmployee) {
this.assuresByEmployee = assuresByEmployee;
}
public List<Assure> getAssuresByAdmin() {
assuresByAdmin = userServicesLocal.findAssuresParAdministrator(administrateurSelected);
return assuresByAdmin;
}
public void setAssuresByAdmin(List<Assure> assuresByAdmin) {
this.assuresByAdmin = assuresByAdmin;
}
public void onRowSelect(SelectEvent event) {
employerSelected = (Employer) event.getObject();
}
public void onRowSelectAssure(SelectEvent event) {
assure = (Assure) event.getObject();
}
public void onRowSelectAdministrateur(SelectEvent event) {
administrateurSelected = (Administrateur) event.getObject();
}
public void onRowUnselect(UnselectEvent event) {
FacesMessage msg = new FacesMessage("Car Selected", ((Employer) event.getObject()).getEmail());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public Employer getEmployerSelected() {
return employerSelected;
}
public void setEmployerSelected(Employer employerSelected) {
this.employerSelected = employerSelected;
}
public void onRowEdit(RowEditEvent event) {
employerSelected = (Employer) event.getObject();
userServicesLocal.saveOrUpdateUser(employerSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowEditAdministrateur(RowEditEvent event) {
administrateurSelected = (Administrateur) event.getObject();
userServicesLocal.saveOrUpdateUser(administrateurSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowEditAssure(RowEditEvent event) {
assureSelected = (Assure) event.getObject();
userServicesLocal.saveOrUpdateUser(assureSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowDelete(RowEditEvent event) {
employerSelected = (Employer) event.getObject();
userServicesLocal.deleteUser(employerSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowDeleteAdministrateur(RowEditEvent event) {
administrateurSelected = (Administrateur) event.getObject();
userServicesLocal.deleteUser(administrateurSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowDeleteAssure(RowEditEvent event) {
assureSelected = (Assure) event.getObject();
userServicesLocal.deleteUser(assureSelected);
// FacesMessage msg = new FacesMessage("Car Edited", ((Car)
// event.getObject()).getId());
// FacesContext.getCurrentInstance().addMessage(null, msg);
}
public PieChartModel getPieModel1() {
return pieModel1;
}
public void setPieModel1(PieChartModel pieModel1) {
this.pieModel1 = pieModel1;
}
public Administrateur getAdministrateurSelected() {
return administrateurSelected;
}
public void setAdministrateurSelected(Administrateur administrateurSelected) {
this.administrateurSelected = administrateurSelected;
}
public Administrateur getAdministrateur() {
return administrateur;
}
public void setAdministrateur(Administrateur administrateur) {
this.administrateur = administrateur;
}
}
The xhtml page:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui" xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrought"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/facelets/template.xhtml">
<ui:define name="pageTitle">admin</ui:define>
<ui:define name="content">
<ul class="breadcrumb">
<li><i class="ace-icon fa fa-home home-icon"></i> <a
href="adminHome.jsf">Acceuil</a></li>
<li class="active">espace Administrateur</li>
</ul>
<!-- /.breadcrumb -->
</ui:define>
<ui:define name="pageContent">
<h:form id="form">
<p:panel header="liste Utilisteurs">
<p:dataTable value="#{utilisateurBean.employersToList}" var="u"
emptyMessage="Aucun utilisateur" selectionMode="single"
selection="#{utilisateurBean.employerSelected}" rowKey="#{u.id}"
editable="true">
<p:ajax event="rowSelect" listener="#{utilisateurBean.onRowSelect}"
oncomplete="PF('d1').show()" update="@form" />
<p:column headerText="Matricule" filterBy="#{u.matricule}"
filterMatchMode="contains">
<p:outputLabel value="#{u.matricule}" />
</p:column>
<p:column headerText="Nombre des assurés">
<p:outputLabel value="#{u.assures.size()}" />
</p:column>
<p:column headerText="Nom">
<p:outputLabel value="#{u.name}" />
</p:column>
<p:column headerText="Prénom">
<p:outputLabel value="#{u.prenom}" />
</p:column>
<p:column headerText="Mot de passe">
<p:outputLabel value="#{u.password}" />
</p:column>
<p:column headerText="Email">
<p:outputLabel value="#{u.email}" />
</p:column>
<p:column headerText="Nombre de demandes">
<p:outputLabel value="#{u.demandes.size()}" />
</p:column>
</p:dataTable>
</p:panel>
<p:dialog header="#{utilisateurBean.employerSelected.id}"
widgetVar="d1" modal="true" showEffect="fade" hideEffect="fade"
resizable="true">
<p:outputPanel style="text-align:center;">
<p:panelGrid id="grid" columns="3">
<p:outputLabel value="Matricule" />
<p:inputText id="i1"
value="#{utilisateurBean.employerSelected.matricule}"
disabled="true">
</p:inputText>
<p:message id="m1" for="i1" />
<p:outputLabel value="Nom" />
<p:inputText id="i2"
value="#{utilisateurBean.employerSelected.name}" required="true"
validatorMessage="Entrer un nom valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex pattern="^[a-zA-Z ]*$" />
<p:ajax event="blur" update="nom" />
</p:inputText>
<p:message for="i2" id="nom" />
<p:outputLabel value="Prénom" />
<p:inputText id="i3"
value="#{utilisateurBean.employerSelected.prenom}"
required="true" validatorMessage="Entrer un prénom valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex pattern="^[a-zA-Z ]*$" />
<p:ajax event="blur" update="prenom" />
</p:inputText>
<p:message for="i3" id="prenom" />
<p:outputLabel value="Mot de passe" />
<p:inputText id="pwd1"
value="#{utilisateurBean.employerSelected.password}"
required="true" requiredMessage="svp indiquez une valeur" />
<p:message for="pwd1" />
<p:outputLabel value="Email" />
<p:inputText id="mail"
value="#{utilisateurBean.employerSelected.email}" required="true"
validatorMessage="Entrer un email valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$"></f:validateRegex>
<p:ajax event="blur" update="email" />
</p:inputText>
<p:message for="mail" id="email" />
</p:panelGrid>
<p:commandButton value="Modifier" icon="ui-icon-disk"
action="#{utilisateurBean.updateUtilisateur()}" update="@form" />
<p:commandButton value="Supprimer" icon="ui-icon-trash"
action="#{utilisateurBean.suprimerUtilisateur()}" update="@form" />
<p:commandButton value="consulter assurés"
oncomplete="PF('d2').show()" update="@(form)" />
</p:outputPanel>
</p:dialog>
<p:dialog header="#{utilisateurBean.employerSelected.id}"
widgetVar="d2" modal="true" showEffect="fade" hideEffect="fade"
resizable="true">
<p:dataTable value="#{utilisateurBean.assuresByEmployee}" var="a"
selectionMode="single" rowKey="#{a.id}">
<p:ajax event="rowSelect"
listener="#{utilisateurBean.onRowSelectAssure}"
oncomplete="PF('d3').show()" update="@form" />
<p:column headerText="Nombre des assurés">
<p:outputLabel value="#{a.name}" />
</p:column>
</p:dataTable>
</p:dialog>
<p:dialog header="#{utilisateurBean.assure.name}" widgetVar="d3"
modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:panelGrid id="grid2" columns="3">
<p:outputLabel value="nom" />
<p:inputText id="assureName" value="#{utilisateurBean.assure.name}"
required="true" validatorMessage="Entrer un nom valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex pattern="^[a-zA-Z ]*$" />
<p:ajax event="blur" update="i9" />
</p:inputText>
<p:message for="assureName" id="i9" />
<p:outputLabel value="Prénom" />
<p:inputText id="assureLastName"
value="#{utilisateurBean.assure.prenom}" required="true"
validatorMessage="Entrer un nom valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex pattern="^[a-zA-Z ]*$" />
<p:ajax event="blur" update="i10" />
</p:inputText>
<p:message for="assureLastName" id="i10" />
<p:outputLabel value="Parenté" />
<p:inputText id="Parenté"
value="#{utilisateurBean.assure.type}" required="true"
validatorMessage="Entrer un nom valide"
requiredMessage="svp indiquez une valeur">
<f:validateRegex pattern="^[a-zA-Z ]*$" />
<p:ajax event="blur" update="i11" />
</p:inputText>
<p:message for="Parenté" id="i11" />
</p:panelGrid>
<p:commandButton value="Modifier" icon="ui-icon-disk"
action="#{utilisateurBean.updateAssure()}" update="@form" />
<p:commandButton value="Supprimer" icon="ui-icon-disk"
action="#{utilisateurBean.deleteAssure()}" />
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
For more details the Please find attached pictures.enter image description here