How to keep selected row after dialog closes Primefaces - primefaces

In Primefaces 5.2, Glassfish 4.0, I am developping a simple CRUD. I have 2 distinct issues related to row selection.
The user clicks on a row in the datatable, this row is highlighted, the user selects "Edit" menu in the contextual menu, a modal window is opened.
1/ When the user press "Cancel" button in the modal window, the dialog is correctly closed. But then if the user selects another row in the datatable, the values displayed in the new modal window corresponds to the first previous selection. How to update the selected values?
2/ When the user press "OK" button in the modal window, the dialog is correctly closed, the datatable is correctly updated. But the updated row in the datatable is not anymore highlighted, the user doesn't know which row has just been updated. Is there a way to keep highlighted the lastly updated row (but to reinitialize the selected values for futher selection) until next click on a row, and in parallel of other focused row?
searchCompany.xhtml code is:
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:contextMenu for="table">
<p:menuitem value="View" update="detail" icon="ui-icon-search" oncomplete="PF('companyDialog').show()"/>
<p:menuitem value="Delete" update="table" icon="ui-icon-close" actionListener="#{dtContextMenuView.deleteCompany}"/>
</p:contextMenu>
<p:dataTable
id="table"
value="#{companyBean.allCompanies}"
var="company"
editable="true"
editmode="row"
widgetVar="cellCompanies"
sortBy="#{company.name}"
scrollable="true"
scrollWidth="1024"
scrollHeight="300"
rowKey="#{company.id}"
selection="#{companyBean.selectedCompany}"
selectionMode="single">
<!-- above: by default table is sorted by Company name -->
<!-- above: to freeze the 2 first columns : frozenColumns="2"-->
<p:column
style="width:150px"
sortBy="#{company.name}"
filterBy="#{company.name}"
filterMatchMode="contains">
<!-- Column is sortable -->
<f:facet name="header">
#{msg['name']} <!-- Title of the column -->
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{company.name}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{company.name}"/>
</f:facet>
</p:cellEditor>
</p:column>
(..)
</p:dataTable>
<p:dialog header="#{msg['detail']}" widgetVar="companyDialog" modal="true" showEffect="fade" resizable="false">
<p:panel id="detail" >
<p:panelGrid columns="2" rendered="#{not empty companyBean.selectedCompany}">
<h:outputText value="#{msg['name']}:" />
<p:inputText value="#{companyBean.selectedCompany.name}" />
<h:outputText value="#{msg['contact']}:" />
<p:inputText value="#{companyBean.selectedCompany.contact}" />
</p:panelGrid>
<p:commandButton action="#{companyBean.updateCompanyEnd}" value='#{msg.OK}' oncomplete="PF('companyDialog').hide();" update="table, :form:msgs"/>
<p:commandButton value='#{msg.cancel}' onclick="PF('companyDialog').hide();"/>
</p:panel>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
The bean code is :
package com.sdzee.bean;
#ManagedBean
#ViewScoped
public class CompanyBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final String CREATE_COMPANY = "createCompany";
private static final String DELETE_COMPANY = "deleteCompany";
private static final String UPDATE_COMPANY = "updateCompany";
private static final String LIST_ALL_COMPANIES = "searchCompany";
private static final String STAY_IN_THE_SAME_PAGE = null;
#EJB
private CompanyFacade companyFacade;
private Company company;
private List<Company> AllCompanies;
#PostConstruct
public void init() {
AllCompanies = companyFacade.findAll();
}
private Company selectedCompany;
public Company getCompany() {
if(company == null){
company = new Company();
}
return company;
}
public void setCompany(Company company) {
this.company = company;
}
public List<Company> getAllCompanies() {
return AllCompanies;
}
public String updateCompanyEnd(){
try {
Company comp = selectedCompany;
companyFacade.update(comp);
} catch (EJBException e) {
FacesContext context = FacesContext.getCurrentInstance();
String texte = context.getApplication().evaluateExpressionGet(context, "#{msg['error']}", String.class);
sendErrorMessageToUser(texte+e);
return STAY_IN_THE_SAME_PAGE;
}
FacesContext context = FacesContext.getCurrentInstance();
String texte = context.getApplication().evaluateExpressionGet(context, "#{msg['update.successful']}", String.class);
FacesMessage message = new FacesMessage(texte, selectedCompany.getName());
FacesContext.getCurrentInstance().addMessage(null, message);
this.selectedCompany = company;
return LIST_ALL_COMPANIES;
}
public String deleteCompanyStart(){
return DELETE_COMPANY;
}
public String deleteCompanyEnd(){
try {
companyFacade.delete(company);
} catch (EJBException e) {
sendErrorMessageToUser("Error. Call the ADM");
return STAY_IN_THE_SAME_PAGE;
}
FacesContext context = FacesContext.getCurrentInstance();
String texte = context.getApplication().evaluateExpressionGet(context, "#{msg['delete.successful']}", String.class);
FacesMessage message = new FacesMessage(texte, company.getName());
FacesContext.getCurrentInstance().addMessage(null, message);
//sendInfoMessageToUser("Operation Complete: Delete");
return LIST_ALL_COMPANIES;
}
public String createCompanyStart(){
return CREATE_COMPANY;
}
public String createCompanyEnd(){
try {
companyFacade.save(company);
} catch (EJBException e) {
sendErrorMessageToUser("Error. Check if the weight is above 0 or call the adm");
return STAY_IN_THE_SAME_PAGE;
}
sendInfoMessageToUser("Operation Complete: Create");
return LIST_ALL_COMPANIES;
}
public String listAllCompanies(){
return LIST_ALL_COMPANIES;
}
private void sendInfoMessageToUser(String message){
FacesContext context = getContext();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
}
private void sendErrorMessageToUser(String message){
FacesContext context = getContext();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
}
private FacesContext getContext() {
FacesContext context = FacesContext.getCurrentInstance();
return context;
}
public Company getSelectedCompany() {
return selectedCompany;
}
public void setSelectedCompany(Company selectedCompany) {
this.selectedCompany = selectedCompany;
}
}

Related

JSF How to pass the value of a CommandButton in bean [duplicate]

I would like to download in primefaces a file whose name can vary.
Here is the code for the controller
#ManagedBean(name="fileDownloadController", eager = true)
#ViewScoped
public class FileDownloadController implements Serializable{
private StreamedContent file;
private String fileName;
public FileDownloadController() {
System.out.println("FileDownloadController sans arg");
System.out.println("getFileName:" + fileName);
InputStream stream = null;
try {
stream = new FileInputStream("D:/myFileDir/"+fileName);
} catch (FileNotFoundException ex) {
Logger.getLogger(FileDownloadController.class.getName()).log(Level.SEVERE, null, ex);
}
file = new DefaultStreamedContent(stream, "image/jpg", fileName);
}
}
And here is the xhtml
<c:forEach items="#{myBean.files}" var="file" >
<p:row>
<p:column>
<p:commandButton id="downloadLink" value="#{file.fileName}" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)" icon="ui-icon-arrowthichk-s" >
<f:setPropertyActionListener target="#{fileDownloadController.fileName}" value="#{file.fileName}"/>
<p:fileDownload value="#{fileDownloadController.file}" />
</p:commandButton>
</p:column>
</p:row>
</c:forEach>
The problem is that in the controller the fileName is null, hence the f:setPropertyActionListener is not configured properly.
However, I can't find a solution.
Why not to pass the fileName directly ...
Bean
#ManagedBean(name="fileDownloadController", eager = true)
#ViewScoped
public class FileDownloadController implements Serializable{
public StreamedContent generateFile(String fileName) {
InputStream stream = null;
try {
stream = new FileInputStream("D:/myFileDir/"+fileName);
} catch (FileNotFoundException ex) {
}
return new DefaultStreamedContent(stream, "image/jpg", fileName);
}
}
XHTML
<p:commandButton id="downloadLink" value="#{file.fileName}"
ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"
icon="ui-icon-arrowthichk-s" >
<p:fileDownload value="#{fileDownloadController.generateFile(file.fileName)}" />
</p:commandButton>
Hope this helps.

command button charge empty values

i'm using jsf2.2 primefaces 6.0 and i create clickable interface that shows the details of the demand throw clicking on the table.After that, i create a command button that shown on 2 specific condition(only when the demand is "Encours" or "Amodifier").My problem is when i try to load the demand details throw "modifier" button it charges empty values.It loads full values only when i preceed it with clicking on the table before to show the demand details.
I need help to solve this problem because i need "modifier" button to update data after that.
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">espace employer</ui:define>
<ui:define name="content">
<ul class="breadcrumb">
<li><i class="ace-icon fa fa-home home-icon"></i> Acceuil</li>
<li class="active">espace Employé</li>
</ul>
<!-- /.breadcrumb -->
</ui:define>
<ui:define name="pageHeader">
<h1></h1>
</ui:define>
<ui:define name="pageContent">
<h:form id="form">
<p:panel header="Mes Demandes">
<p:dataTable id="tt1" selectionMode="single" rowKey="#{d.id}"
value="#{demandeBean.allDemandesParEmployer}" var="d"
emptyMessage="Aucune demande">
<p:ajax event="rowSelect" listener="#{demandeBean.onRowSelect}"
oncomplete="PF('d3').show()" update=":form:d3" />
<p:column headerText="Date">
<h:outputText value="#{d.dateDeDepot}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"
timeZone="GMT+1:00" />
</h:outputText>
</p:column>
<p:column headerText="État">
<h:outputText value="#{d.etatDemande}" />
</p:column>
<p:column style="text-align: center" headerText="Visualiser">
<p:commandButton update="#form" oncomplete="PF('diag').show()"
icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{d}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
<p:column headerText="Action">
<p:commandButton value="Modifier" icon="ui-icon-disk" onclick="PF('d3').show();"
rendered="#{d.etatDemande == 'ENCOURS'|| d.etatDemande == 'AMODIFIER'}">
<f:setPropertyActionListener value="#{d}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
<p:panel rendered="#{not empty demandeBean.allDemandesParAssures}"
header="Mes assurés demandes">
<p:dataTable value="#{demandeBean.allDemandesParAssures}" var="d"
selectionMode="single" rowKey="#{d.id}"
emptyMessage="Aucune demande">
<p:ajax event="rowSelect" listener="#{demandeBean.onRowSelect}"
oncomplete="PF('d2').show()" update=":form:d2" />
<p:column headerText="État">
<h:outputText value="#{d.dateDeDepot}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"
timeZone="GMT+1:00" />
</h:outputText>
</p:column>
<p:column headerText="Assuré">
<h:outputText value="#{d.employer.name} #{d.employer.prenom}" />
</p:column>
<p:column headerText="État">
<h:outputText value="#{d.etatDemande}" />
</p:column>
<p:column style="text-align: center" headerText="Visualiser">
<p:commandButton update="#form" oncomplete="PF('diag').show()"
icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{d}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
<p:dialog header="Détails demande" widgetVar="d2" modal="true"
id="d2" dynamic="true" showEffect="fade" hideEffect="fade"
resizable="true" position="center">
<p:outputPanel id="p2" style="text-align:center;">
<p:dataTable
value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
<p:column headerText="Acte">
<h:outputText value="#{d.acteMedical.typeActe}" />
</p:column>
<p:column headerText="Montant">
<h:outputText value="#{d.montant}" />
</p:column>
<p:column headerText="Date">
<h:outputText value="#{d.dateActe}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column style="text-align: center" headerText="images"
width="10%">
<p:commandButton update="#form" oncomplete="PF('diag').show()"
rendered="#{not empty a.images}" icon="ui-icon-search"
title="View">
<f:setPropertyActionListener value="#{a}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
<p:dialog header="Détails demande" widgetVar="d3" modal="true"
id="d3" dynamic="true" showEffect="fade" hideEffect="fade"
resizable="true" position="center">
<p:outputPanel id="p3" style="text-align:center;">
<p:dataTable
value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
<p:column headerText="Acte">
<h:outputText value="#{d.acteMedical.typeActe}" />
</p:column>
<p:column headerText="Montant">
<h:outputText value="#{d.montant}" />
</p:column>
<p:column headerText="Date">
<h:outputText value="#{d.dateActe}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column style="text-align: center" headerText="images"
width="10%">
<p:commandButton update="#form" oncomplete="PF('diag').show()"
rendered="#{not empty a.images}" icon="ui-icon-search"
title="View">
<f:setPropertyActionListener value="#{a}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
<p:dialog header="Détails demande" widgetVar="d4" modal="true"
id="d4" dynamic="true" showEffect="fade" hideEffect="fade"
resizable="true" position="center">
<p:outputPanel id="p4" style="text-align:center;">
<p:dataTable
value="#{demandeBean.demandeSelectionnee.detailDemandes}" var="d">
<p:column headerText="Acte">
<h:outputText value="#{d.acteMedical.typeActe}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
<p:dialog header="images" widgetVar="diag" modal="true"
showEffect="fade" hideEffect="fade" resizable="true"
position="center" height="500" width="650">
<p:outputPanel id="gal" style="text-align:center;">
<p:galleria value="#{demandeBean.demandeSelectionnee.images}"
showFilmstrip="true" autoPlay="false" var="image">
<p:graphicImage
value="http://localhost:18080/openCars/images/#{image}"
alt="Image Description for #{image}" title="#{image}" />
</p:galleria>
</p:outputPanel>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
java Bean:
package mBeans;
import java.util.ArrayList;
import java.util.Date;
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.CellEditEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import persistence.ActeMedical;
import persistence.Assure;
import persistence.Demande;
import persistence.DetailDemande;
import persistence.EtatDemande;
import persistence.User;
import services.DemandeServicesLocal;
import services.UserServicesLocal;
#ManagedBean
#ViewScoped
public class DemandeBean {
private List<String> images = new ArrayList<>();
private String matriculeForAdminToAdd;
private List<DetailDemande> detailDemandesTMP = new ArrayList<>();
private ActeMedical acteMedical = new ActeMedical();
private List<ActeMedical> acteMedicalsToAdd = new ArrayList<>();
private Integer idOf;
private List<Demande> allDemandes = new ArrayList<>();
private List<Demande> allDemandesParAssures = new ArrayList<>();
private List<Demande> allDemandesParEmployer = new ArrayList<>();
private Demande demande = new Demande();
private Demande demandeSelectionnee = new Demande();
private List<String> etats = new ArrayList<>();
private String etatChoisi = "";
private Date dateActe;
private Double montant;
private ActeMedical acteMedicalSelection = new ActeMedical();
private List<ActeMedical> acteMedicals = new ArrayList<>();
private List<Assure> assuresParEmployee = new ArrayList<>();
#EJB
private DemandeServicesLocal demandeServicesLocal;
#EJB
private UserServicesLocal userServicesLocal;
#ManagedProperty(value = "#{identity}")
private Identity identity;
#PostConstruct
public void init() {
etats.add("ENCOURS");
etats.add("ACCEPTE");
etats.add("AMODIFIER");
}
public List<String> completeTheme(String query) {
List<User> users = userServicesLocal.findAllUsers();
List<String> list = new ArrayList<>();
for (User u : users) {
list.add(u.getMatricule());
}
return list;
}
public void addDetailToList() {
DetailDemande detailDemande = new DetailDemande(dateActe, demande, acteMedical, montant);
detailDemandesTMP.add(detailDemande);
detailDemande = new DetailDemande();
vider();
}
public void deleteDetailToList(DetailDemande detailDemande) {
detailDemandesTMP.remove(detailDemande);
detailDemande = new DetailDemande();
vider();
}
public String doAddDemande() {
demande.setImages(images);
demande.setEmployer(demandeServicesLocal.findUserById(idOf));
if (!detailDemandesTMP.isEmpty()) {
Demande d = demandeServicesLocal.addDemande(demande);
for (DetailDemande t : detailDemandesTMP) {
demandeServicesLocal.ajouterDetailDemande(t.getDateActe(), d, t.getActeMedical(), t.getMontant());
}
demande = new Demande();
dateActe = null;
montant = null;
detailDemandesTMP = new ArrayList<>();
return "/pages/listDemandesByEmployer?faces-redirect=true";
} else {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Veuillez ajouter un acte médical", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
return "";
}
}
public String doAddDemandeBtAdmin() {
demande.setImages(images);
demande.setEmployer(demandeServicesLocal.findUserByMatricule(matriculeForAdminToAdd));
if (!detailDemandesTMP.isEmpty()) {
Demande d = demandeServicesLocal.addDemande(demande);
for (DetailDemande t : detailDemandesTMP) {
demandeServicesLocal.ajouterDetailDemande(t.getDateActe(), d, t.getActeMedical(), t.getMontant());
}
demande = new Demande();
dateActe = null;
montant = null;
detailDemandesTMP = new ArrayList<>();
matriculeForAdminToAdd = null;
return "/pages/listDemandes?faces-redirect=true";
} else {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Veuillez ajouter un acte médical", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
return "";
}
}
public void doSome() {
System.out.println(idOf);
}
public void vider() {
dateActe = null;
montant = 0D;
}
public void doCreateDetail() {
demandeServicesLocal.ajouterDetailDemande(dateActe, demande, acteMedicalSelection, montant);
}
public List<Demande> getAllDemandes() {
allDemandes = demandeServicesLocal.findAllDemandes();
return allDemandes;
}
public void traiterDemande() {
if (etatChoisi.equals("ACCEPTE")) {
demandeServicesLocal.addDemande(demandeSelectionnee);
} else if (etatChoisi.equals("AMODIFIER")) {
demandeSelectionnee.setEtatDemande(EtatDemande.AMODIFIER);
demandeServicesLocal.addDemande(demandeSelectionnee);
}
}
public int hatImagesSize() {
System.out.println(images.size());
return images.size();
}
public void setAllDemandes(List<Demande> allDemandes) {
this.allDemandes = allDemandes;
}
public Demande getDemande() {
return demande;
}
public void setDemande(Demande demande) {
this.demande = demande;
}
public List<Demande> getAllDemandesParEmployer() {
allDemandesParEmployer = demandeServicesLocal.findAllDemandesParEmployer(identity.getUser());
return allDemandesParEmployer;
}
public void setAllDemandesParEmployer(List<Demande> allDemandesParEmployer) {
this.allDemandesParEmployer = allDemandesParEmployer;
}
public DemandeServicesLocal getDemandeServicesLocal() {
return demandeServicesLocal;
}
public void setDemandeServicesLocal(DemandeServicesLocal demandeServicesLocal) {
this.demandeServicesLocal = demandeServicesLocal;
}
public Identity getIdentity() {
return identity;
}
public void setIdentity(Identity identity) {
this.identity = identity;
}
public void onRowSelect(SelectEvent event) {
demandeSelectionnee = (Demande) event.getObject();
FacesMessage msg = new FacesMessage("Car Selected", ((Demande) event.getObject()).getEtatDemande().toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowUnselect(UnselectEvent event) {
FacesMessage msg = new FacesMessage("Car Unselected",
((Demande) event.getObject()).getEtatDemande().toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public Demande getDemandeSelectionnee() {
return demandeSelectionnee;
}
public void setDemandeSelectionnee(Demande demandeSelectionnee) {
this.demandeSelectionnee = demandeSelectionnee;
}
public List<String> getEtats() {
return etats;
}
public void setEtats(List<String> etats) {
this.etats = etats;
}
public String getEtatChoisi() {
return etatChoisi;
}
public void setEtatChoisi(String etatChoisi) {
this.etatChoisi = etatChoisi;
}
public Date getDateActe() {
dateActe = new Date();
return dateActe;
}
public void setDateActe(Date dateActe) {
this.dateActe = dateActe;
}
public Double getMontant() {
return montant;
}
public void setMontant(Double montant) {
this.montant = montant;
}
public ActeMedical getActeMedicalSelection() {
return acteMedicalSelection;
}
public void setActeMedicalSelection(ActeMedical acteMedicalSelection) {
this.acteMedicalSelection = acteMedicalSelection;
}
public List<ActeMedical> getActeMedicals() {
acteMedicals = demandeServicesLocal.findAllActe();
return acteMedicals;
}
public void setActeMedicals(List<ActeMedical> acteMedicals) {
this.acteMedicals = acteMedicals;
}
public List<Assure> getAssuresParEmployee() {
assuresParEmployee = demandeServicesLocal.findAssuresByEmployee(identity.getUser());
return assuresParEmployee;
}
public void setAssuresParEmployee(List<Assure> assuresParEmployee) {
this.assuresParEmployee = assuresParEmployee;
}
public Integer getIdOf() {
return idOf;
}
public void setIdOf(Integer idOf) {
this.idOf = idOf;
}
public List<Demande> getAllDemandesParAssures() {
allDemandesParAssures = demandeServicesLocal.findAllDemandesParAssureDeEmployer(identity.getUser());
return allDemandesParAssures;
}
public void setAllDemandesParAssures(List<Demande> allDemandesParAssures) {
this.allDemandesParAssures = allDemandesParAssures;
}
public ActeMedical getActeMedical() {
return acteMedical;
}
public void setActeMedical(ActeMedical acteMedical) {
this.acteMedical = acteMedical;
}
public List<ActeMedical> getActeMedicalsToAdd() {
return acteMedicalsToAdd;
}
public void setActeMedicalsToAdd(List<ActeMedical> acteMedicalsToAdd) {
this.acteMedicalsToAdd = acteMedicalsToAdd;
}
public List<DetailDemande> getDetailDemandesTMP() {
return detailDemandesTMP;
}
public void setDetailDemandesTMP(List<DetailDemande> detailDemandesTMP) {
this.detailDemandesTMP = detailDemandesTMP;
}
public String getMatriculeForAdminToAdd() {
return matriculeForAdminToAdd;
}
public void setMatriculeForAdminToAdd(String matriculeForAdminToAdd) {
this.matriculeForAdminToAdd = matriculeForAdminToAdd;
}
public List<String> getImages() {
return images;
}
public void setImages(List<String> images) {
this.images = images;
}
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
demandeSelectionnee = demandeServicesLocal.findDemandeById(Integer.valueOf(event.getRowKey()));
if (newValue != null && !newValue.equals(oldValue)) {
if (newValue.equals("ENCOURS")) {
demandeSelectionnee.setEtatDemande(EtatDemande.ENCOURS);
demandeServicesLocal.addDemande(demandeSelectionnee);
} else if (newValue.equals("AMODIFIER")) {
demandeSelectionnee.setEtatDemande(EtatDemande.AMODIFIER);
demandeServicesLocal.addDemande(demandeSelectionnee);
} else if (newValue.equals("ACCEPTE")) {
demandeSelectionnee.setEtatDemande(EtatDemande.TRANSMISE);
demandeServicesLocal.addDemande(demandeSelectionnee);
}
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed",
"Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
If I was understand right your problem, first of all I think your button must have oncomplete="PF('d3').show();" instead of onclick="PF('d3').show();"
and it must have attribute update="d3" where d3 to be the right dialog widget ID.
Let's explain how it works: first click the button - which updates the property in javaBean, after that it will update the dialog with the new changes from the back-end. Finally, after the request ends, it will open the dialog.

Use List for source in datatable with lazyLoading

I have the list with very data. I want to show data in Primeface data table with lazy loading ability. now I show data normal in data Table, but it is slow.
How can use lazy loading ability?
XHTML File :
<ui:composition template="template.xhtml">
<ui:define name="content">
<p:panel id="pnlLogInformationPage">
<h:form id="logInformation">
<div class="contentContainer-full-left">
<p:dataTable var="log" value="#{logInformationMB.logInformationList}" id="logTable"
width="100%" liveResize="true">
<p:column headerText="ID" sortBy="Id">
<h:outputText value="#{logInformation.Id}" />
</p:column>
<p:column headerText="Name" sortBy="Name">
<h:outputText value="#{logInformation.Name}" />
</p:column>
</p:dataTable>
</div>
</h:form>
</p:panel>
</ui:define>
ManageBean File:
#ManagedBean(name = "logInformationMB")
#ViewScoped
public class LogManagedBean implements Serializable {
#PostConstruct
public void initComponents() {
loadLogInformation();
}
public List<LogInformationDTO> getLogInformationList() {
return logInformationList;
}
public void setLogInformationList(final List<LogInformationDTO> pLogInformationList) {
logInformationList = pLogInformationList;
}
public void loadLoagInformation(final ComponentSystemEvent event) {
setLogLInformationlist(getLogInformationList();
}
public void loadInformationProtokolle() {
loadInformationProtokolle(null);
}
public List<LogInformationDTO> getLogInformation() {
final List<LogInformationDTO> lcResult = new ArrayList<LogInformationDTO>();
....
return lcResult;
}
}
According to your code, you didn't use lazyloading. you just get all your datas.
It will be slow when your data is too big.
See my steps below:
1- Instead of using #{logInformationMB.logInformationList}, you need to create new class which extend LazyDataModel class and create a service that can get data page by page.
public class LogInformationDataModel extends LazyDataModel<LogInformationDTO> {
private List<LogInformationDTO> logInformationList;
private LogInformationService logInformationService = new LogInformationService();
#Override
public List<LogInformationDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
// TODO implement sort
setRowCount(logInformationService.count(filters));
logInformationList = logInformationService.list(first / pageSize, pageSize, sortField, sort, filters);
return logInformationList;
}
#Override
public LogInformationDTO getRowData(String rowKey) {
for(LogInformationDTO logInformation : logInformationList) {
if(logInformation.getId().equals(rowKey))
return logInformation;
}
return null;
}
#Override
public Object getRowKey(LogInformationDTO logInformation) {
return logInformation.getId();
}
}
2- Register data model in your Manage bean
#ManagedBean(name = "logInformationMB")
#ViewScoped
public class LogManagedBean implements Serializable {
private LogInformationDataModel dataModel = new LogInformationDataModel();
public LogInformationDataModel getDataModel() {
return dataModel;
}
}
3- Add lazy attribe (lazy="true") to your p:dataTable and using pagination
<p:dataTable var="log" value="#{logInformationMB.dataModel}" var="logInformation" id="logTable"
width="100%"
lazy="true"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50,100"
>
<p:column headerText="ID" sortBy="Id">
<h:outputText value="#{logInformation.Id}" />
</p:column>
<p:column headerText="Name" sortBy="Name">
<h:outputText value="#{logInformation.Name}" />
</p:column>
</p:dataTable>
I Hope my answer could solve your issue.
Below is the link you can check :
Primefaces lazydatamodel

PrimeFaces SelectOneRadio

I have one req , where I have a datable , which has x columns. One column contains 3 radio buttons .Which i am able to display . But my problem is I want one radio button to be selected by default .
What I am doing : On Load of datatable i am creating one variable (also i tried with SlectIte list) , but unable to get checked value.
Can anyone provide a simple working example?
This is my demonstration which present how to default radio value in datatable
XHTML
<h:form>
<p:dataTable var="catalog" value="#{radioView.catalogs}">
<p:column headerText="City">
<p:selectOneRadio id="city"
value="#{catalog.city}"
columns="3">
<f:selectItems value="#{radioView.cities}"
var="c"
itemLabel="#{city}"
itemValue="#{city}"/>
</p:selectOneRadio>
</p:column>
</p:dataTable>
<p:commandButton value="changeSelection"
process="#form"
update="#form"
actionListener="#{radioView.changeSelection}"/>
<p:commandButton value="submit"
process="#form"
update="#form"
actionListener="#{radioView.submit}"/>
</h:form>
ManagedBean
#ManagedBean
public class RadioView {
private List<Catalog> catalogs;
private List<String> cities;
#PostConstruct
public void init() {
cities = new ArrayList<String>();
cities.add("San Francisco");
cities.add("London");
cities.add("Paris");
//default radio value
Catalog c1 = new Catalog("San Francisco");
Catalog c2 = new Catalog("London");
Catalog c3 = new Catalog("Paris");
Catalog c4 = new Catalog("London");
catalogs = new ArrayList<Catalog>();
catalogs.add(c1);
catalogs.add(c2);
catalogs.add(c3);
catalogs.add(c4);
}
public List<Catalog> getCatalogs() {
return catalogs;
}
public void setCatalogs(List<Catalog> catalogs) {
this.catalogs = catalogs;
}
public List<String> getCities() {
return cities;
}
public void changeSelection(ActionEvent event){
for (Catalog catalog : catalogs) {
catalog.setCity("San Francisco");
}
}
public void submit(ActionEvent event) {
for (Catalog catalog : catalogs) {
System.out.println(catalog.getCity());
}
}
}
Domain
public class Catalog implements Serializable{
private String city;
public Catalog(String city){
this.city = city;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}

Action of CommandLink/CommandButton in p:treeTable is not invoked

I download primefaces 3.1, add to my project tried to add a commandButton/commandLink into a column of a treeTable
but action of commandButton/commandLink in a column is not invoked except the root row.
What may the problem be? Thanks
EDIT:
treeTable in xhtml:
<p:treeTable var="catalog" value="#{catalogSelectBean.root}" lazy="true" selection="#{catalogSelectBean.selectedNode}" selectionMode="single">
<p:column>
<f:facet name="header">
<h:outputText value="Katalog Name" />
</f:facet>
<h:outputText value="#{catalog.name}" />
</p:column>
<p:column width="100">
<f:facet name="header">
<h:outputText value="Katalog Desc"/>
</f:facet>
<h:outputText value="#{catalog.description}"/>
</p:column>
<p:column>
<p:commandButton action="#{formProductRelationView.updateProductListForSelectedCatalog()}"
update=":main_form:selectProductTable"
value="Bring Products">
</p:commandButton>
</p:column>
</p:treeTable>
Bean:
#Component("catalogSelectBean")
#Scope("request")
public class CatalogSelectBean implements Serializable {
private static final long serialVersionUID = 1L;
#Autowired
private CatalogService catalogService;
private TreeNode root;
private TreeNode selectedNode;
private DualListModel<Catalog> pickListCatalogs;
public TreeNode getRoot() {
return root;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public void onNodeSelect(NodeSelectEvent event) {
Catalog g = (Catalog)event.getTreeNode().getData();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", g.getName());
FacesContext.getCurrentInstance().addMessage(null, message);
}
public CatalogSelectBean() {
}
#PostConstruct
public void unLoad(){
createRoot();
createPickListModel();
}
private void createPickListModel() {
//Players
List<Catalog> source = catalogService.loadChilds(catalogService.getRootCatalog());
List<Catalog> target = new ArrayList<Catalog>();
pickListCatalogs = new DualListModel<Catalog>(source, target);
}
private void createRoot() {
Catalog g = null ;
g = catalogService.getRootCatalog();
root = new DefaultTreeNode("Root", null);
TreeNode caRoot = new DefaultTreeNode(g,root);
generateTree(caRoot,g);
}
private void generateTree(TreeNode subRoot, Catalog g) {
for(Catalog p : g.getChildCatalogs()){
TreeNode node0 = new DefaultTreeNode(p,subRoot);
if(p.getChildCatalogs()!= null && p.getChildCatalogs().size()>0)
generateTree(node0, p);
}
}
public void resetTree() {
root.setSelected(false);
}
public DualListModel<Catalog> getPickListCatalogs() {
return pickListCatalogs;
}
}
Also i have a formProductRelationView bean which has the updateProductListForSelectedCatalog() method.
Thanks for attention.