I have two datatables in the same page. The first one is loaded when the page loads. The second one is loaded when a row is clicked. I have a command button in each row. In the first datatable works fine. But, in the second one, the parameter value is null. It only works if I use immediate attribute equals true. Does someone know why?
My page:
<h:form id="form">
<p:dataTable id="dtOwner" selectionMode="single" var="owner" value="#{ownerBean.retornaOwners}"
selection="#{ownerBean.ownerSelected}" rowKey="#{owner.id_owner}">
<p:ajax update="form:pgCars" process="#form" event="rowSelect" listener="#{ownerBean.onRowSelect}" />
<p:column headerText="Actions">
<p:commandButton value="Exclude" actionListener="#{ownerBean.excludeOwner(owner)}"></p:commandButton>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{owner.name}"></h:outputText>
</p:column>
<p:column headerText="Surname">
<h:outputText value="#{owner.surname}"></h:outputText>
</p:column>
</p:dataTable>
<p:panelGrid id="pgCars">
<p:dataTable id="dtCars" var="car" value="#{ownerBean.ownerSelected.listCars}"
selection="#{ownerBean.ownerSelected}" rowKey="#{owner.id_owner}">
<p:column headerText="Actions" >
<p:commandButton value="Exclude" process="#all" update="form" actionListener="#{ownerBean.excludeCar(car)}"></p:commandButton>
</p:column>
<p:column headerText="id_Car" >
<h:outputText value="#{car.id_car}"></h:outputText>
</p:column>
<p:column headerText="id_owner" >
<h:outputText value="#{car.id_owner}"></h:outputText>
</p:column>
<p:column headerText="tipo_carro" >
<h:outputText value="#{car.tipo_carro}"></h:outputText>
</p:column>
<p:column headerText="modelo_carro" >
<h:outputText value="#{car.modelo_carro}"></h:outputText>
</p:column>
</p:dataTable>
</p:panelGrid>
</h:form>
My bean:
package com.tutorial;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
#ManagedBean(name="ownerBean")
#SessionScoped
public class OwnerBean {
#ManagedProperty(value = "#{ownerDAO}")
private OwnerDAO ownerDAO;
public void setOwnerDAO(OwnerDAO ownerDAO) {
this.ownerDAO = ownerDAO;
}
private Owner ownerSelected;
public void excludeOwner(Owner owner) {
System.out.println("Excluding " + owner.getName());
}
public void excludeCar(Car car) {
System.out.println("Excluding car " + car.getModelo_carro());
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage("Owner Selected", Integer.toString(
( (Owner) event.getObject()).getId_owner()));
FacesContext.getCurrentInstance().addMessage(null, msg);
ownerSelected = (Owner) event.getObject();
ownerSelected.setListCars(new ArrayList<Car>());
ownerSelected.setListCars(ownerDAO.getCars(ownerSelected));
}
public List<Owner> getRetornaOwners() {
List<Owner> list = new ArrayList<>();
try {
list = ownerDAO.getOwners();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public Owner getOwnerSelected() {
return ownerSelected;
}
public void setOwnerSelected(Owner ownerSelected) {
this.ownerSelected = ownerSelected;
}
}
The excludeOwner(Owner owner) function works fine, but the excludeCars(Car car) doesn't. I always get null in car value.
Thanks
I use process="#this" in the commandButton and works. Also, I remove update attribute from commandButton and process attribute from ajax. Thanks a lot
Ajax:
<p:ajax update="form:dtCars" event="rowSelect" listener="#{ownerBean.onRowSelect}" />
Command button:
<p:commandButton value="Exclude" process="#this" actionListener="#{ownerBean.excludeCar(car)}"></p:commandButton>
Related
I have a datatable where one of the columns is editable.
As long as i dont use my filter i can navigate through my list and can edit the entry in any row i want. I dont get any errors and my changes are persisted in the DB correctly.
But after i once used any of the filter everything goes sideways. The filter itself works properly.
But when i now try to edit any entry the event.oldValue() from my CellEditEvent is always null and i cant persist my entries.
And only the first page of my paginator is filled with data. Every other page is empty.
Here is the view:
<div class="Container100">
<p:dataTable paginator="true" rows="15" var="listReportingParticipantOverview" value="#{reportingBean.listReportingParticipantOverview}"
id="participantOverviewId" widgetVar="participantOverviewId"
editable="true" editMode="cell" editInitEvent="dblclick"
emptyMessage="#{msg['system.no_result']}"
filteredValue="#{reportingBean.filteredListReportingParticipantOverview}">
<p:ajax event="cellEdit" listener="#{reportingBean.onCellEdit}" update=":reportingForm:msgs"/>
<p:column headerText="#{msg['model.reporting.participant_overview.name']}" filterBy="#{listReportingParticipantOverview.name}" filterMatchMode="contains">
<h:outputText value="#{listReportingParticipantOverview.name}" />
</p:column>
<p:column headerText="#{msg['model.reporting.participant_overview.dateOfBirth']}" filterBy="#{listReportingParticipantOverview.dateOfBirth}" filterMatchMode="contains">
<h:outputText value="#{listReportingParticipantOverview.dateOfBirth}" />
</p:column>
<p:column headerText="#{msg['model.reporting.participant_overview.email']}" filterBy="#{listReportingParticipantOverview.email}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{listReportingParticipantOverview.email}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{listReportingParticipantOverview.email}" style="width:100%" label="name"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</div>
Here is the bean:
#SessionScoped
#ManagedBean(name = "reportingBean2")
public class ReportingBean2 extends BeanController implements Serializable {
List<ReportingParticipantOverview> listReportingParticipantOverview = new ArrayList<ReportingParticipantOverview>();
List<ReportingParticipantOverview> filteredListReportingParticipantOverview;
ContactRepository contactRepository;
ContactRepository contactRepositoryOtherDBContext;
CommunicationRepository communicationRepositoryOtherDBContext;
private AbstractApplicationContext otherDBContext;
public void initData() {
this.listReportingParticipantOverview = this.contactRepositoryOtherDBContext
.selectParticipantOverviewReporting();
}
#PostConstruct
public void init() {
otherDBContext = new ClassPathXmlApplicationContext("applicationContext_otherDB.xml");
this.contactRepository = this.getApplicationContext().getBean(ContactRepository.class);
this.contactRepositoryOtherDBContext = otherDBContext.getBean(ContactRepository.class);
this.communicationRepositoryOtherDBContext = otherDBContext.getBean(CommunicationRepository.class);
}
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
// ...
}
public List<ReportingParticipantOverview> getListReportingParticipantOverview() {
return listReportingParticipantOverview;
}
public void setListReportingParticipantOverview(
List<ReportingParticipantOverview> listReportingParticipantOverview) {
this.listReportingParticipantOverview = listReportingParticipantOverview;
}
public List<ReportingParticipantOverview> getFilteredListReportingParticipantOverview() {
return filteredListReportingParticipantOverview;
}
public void setFilteredListReportingParticipantOverview(
List<ReportingParticipantOverview> filteredListReportingParticipantOverview) {
this.filteredListReportingParticipantOverview = filteredListReportingParticipantOverview;
}
}
}
I am using Java 8, Eclipse 2021-03 and Primefaces 10.0.0.
Any help appreciated :-)
I am trying to perform a row edit in primefaces databable. My problem is when I key in new value in inputText in CellEditor
and click edit (primefaces icon) onCellEdit method is calledsuccessfully but does not pick the newly value in the inputText it pick value that was initially in the datatable. What Am I doing wrong? I am using primefaces 3.5
Here in jsf code
<h:form id="form1">
<p:growl id="messages" showDetail="true"/>
<p:panel header="Registered Devices" style="min-height: 400px;" id="paneldevices">
<p:dataTable emptyMessage="No Device Registered" editable="true" widgetVar="deviceTable" id="idGrid" value="#{deviceMgdBean.devices}" var="item" >
<p:ajax event="rowEdit" listener="#{deviceMgdBean.onCellEdit()}" update=":form1:messages"/>
<p:ajax event="rowEditCancel" listener="#{deviceMgdBean.onCancel}" update=":form1:messages" />
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Device_name"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{item.device_name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.device_name}" style="width:80%" />
</f:facet>
</p:cellEditor>
</p:column>
</h:form>
Here is my managed Bean
#ManagedBean
#ViewScoped
public class DeviceMgdBean implements Serializable {
public List<Devices> getDevices()
{
List<Devices> l=getDevdao().getDevices();//devices fetched from database
return l;
}
public void onCellEdit(RowEditEvent event)
{
Devices devo=(Devices) event.getObject();
FacesMessage msg = new FacesMessage("Device Edit","Test:"+devo.getDeviceName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event)
{
FacesMessage msg = new FacesMessage("Item Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
Devices devo=(Devices) event.getObject();
}
}
class Devices {
private int device_id;
private String device_name;
//getter and setters
}
private List<Devices> l;
public List<Devices> getDevices() {
if(l==null) l=getDevdao().getDevices();//devices fetched from database
return l;
}
I'm updating my web application to PF5.1 (was in PF4.0)
A simple update on the <p:dataTable> component now destroy totally my datatable FILTER.
update=":#{p:component('tbl_queue')}"
I had to change my column filter because of the new PF5.1 version, so I modified my filters with :
<f:facet name="filter" >
<p:selectOneMenu ... >
<f:selectItem ... />
<f:selectItems ... />
</p:selectOneMenu>
</f:facet>
And the old filters version was :
<p:column id="..."
filterBy=...
filterOptions="..."
filterMatchMode="exact"
>
...
</p:column>
EDIT : My request is simple, it's to do a remove on a filtered datatable by selection (and to keep the filter alive). It was possible on PF4.0, it seems not of PF5.
Like that :
Step 1 : Filter the datatable
Step 2 : Remove one line by clicking 'Envoyer' = Remove (J91GT N9 03:17:00)
It's working fine on PF4, but I can't find a solution to do the same in PF5.
EDIT 2:
<p:dataTable id="tbl_queue" var="c"
value="#{queueModificationController.cartQueue}"
widgetVar="queueTable"
filteredValue="#{queueModificationController.filteredCartQueue}"
rowKey = "#{c.id}"
>
<p:column
id="Bumper_column"
filterBy="#{c.name_bumper}"
headerText="Bumper"
filterMatchMode="exact"
>
<f:facet name="filter" >
<p:selectOneMenu onchange="PF('queueTable').filter()" id="selectFilterBumper" >
<f:selectItem itemLabel="Aucun" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{queueModificationController.nameBumperOptionsString}" />
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{c.name_bumper}" />
</p:column>
<p:column>
//...
</p:column>
//...
//...
<p:column id="validation_column"
headerText="Validation">
<p:commandButton
action="#{productionQueue.updateAfterSending()}"
value="Validation"
update=":#{p:component('tbl_queue')}"
<f:setPropertyActionListener value="#{c}"
target="#{productionQueue.selectedCart}" />
</p:commandButton>
</p:column>
</p:dataTable>
--
#ManagedBean(name = "productionQueue")
#SessionScoped
private ArrayList<CartInQueueConsult> cartQueue; //filled by Database in bean initialisation
private ArrayList<CartInQueueConsult> filteredCartQueue = new ArrayList<CartInQueueConsult>(cartQueue);
public void updateAfterSending()
{
... (remove in database)
filteredCartQueue.remove(selectedCart);
cartQueue.remove(selectedCart);
}
EDIT : MCVE Example of the error :
Errors :
- 1: The filter is not working (strange thing because all of my filters are working properly on no-MVCE example
- 2: When you remove a Line with the button "Remove" the Filters are broken (my initial problem)
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;
#ManagedBean(name = "testController")
#ViewScoped
public class TestController implements Serializable
{
private ArrayList<String> cartQueue;
private String selectedCart;
private ArrayList<String> filteredCartQueue;
private SelectItem nameBumperOptionsString[] = {new SelectItem(1,"1"),new SelectItem(2,"2"),new SelectItem(3,"3"),new SelectItem(4,"4"),new SelectItem(5,"5")};
#PostConstruct
public void initialize()
{
cartQueue = new ArrayList<String>();
cartQueue.add("1");
cartQueue.add("2");
cartQueue.add("3");
cartQueue.add("4");
cartQueue.add("5");
cartQueue.add("6");
filteredCartQueue = cartQueue;
}
public void remove()
{
try
{
filteredCartQueue.remove(selectedCart);
cartQueue.remove(selectedCart);
}
catch (Exception ex)
{
System.out.println("EXCEPTION : "+ ex.getMessage());
}
}
public ArrayList<String> getFilteredCartQueue() {
return filteredCartQueue;
}
public void setFilteredCartQueue(ArrayList<String> filteredCartQueue) {
this.filteredCartQueue = filteredCartQueue;
}
public SelectItem[] getNameBumperOptionsString() {
return nameBumperOptionsString;
}
public void setNameBumperOptionsString(SelectItem nameBumperOptionsString[]) {
this.nameBumperOptionsString = nameBumperOptionsString;
}
public ArrayList<String> getCartQueue() {
return cartQueue;
}
public void setCartQueue(ArrayList<String> cartQueue) {
this.cartQueue = cartQueue;
}
public String getSelectedCart() {
return selectedCart;
}
public void setSelectedCart(String selectedCart) {
this.selectedCart = selectedCart;
}
}
_
<p:dataTable
id="test_queue" var="c"
value="#{testController.cartQueue}" widgetVar="testTable"
emptyMessage="Pas de file d'attente"
filteredValue="#{testController.filteredCartQueue}"
paginator="true"
currentPageReportTemplate="Nb Rows : {totalRecords}"
paginatorTemplate="{CurrentPageReport}"
>
<p:column id="number_column"
filterBy="#{c}"
headerText="Number"
filterMatchMode="exact"
>
<f:facet name="filter" >
<p:selectOneMenu onchange="PF('testTable').filter()" >
<f:selectItem itemLabel="Nothing" itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{testController.nameBumperOptionsString}" />
</p:selectOneMenu>
</f:facet>
<center>
<h:outputText value="#{c}" />
</center>
</p:column>
<p:column headerText="Remove">
<center>
<p:commandButton
action="#{testController.remove()}"
value="Remove"
update="test_queue" >
<f:setPropertyActionListener value="#{c}" target="#{testController.selectedCart}" />
</p:commandButton>
</center>
</p:column>
</p:dataTable>
--
EDIT 3 : Lib :
Your code looked fine and it worked fine for me too. I was never able to reproduce your problem and therefore I was not able to pinpoint the true root cause.
Your concrete problem is most likely caused by having a dirty runtime classpath with a bunch of servletcontainer specific libraries (never do that!) and a heavily outdated JSF implementation (more than 5 years old). And indeed, when you cleaned up the runtime classpath and upgraded the JSF implementation, it worked fine for you too.
I have a table showing list from a bean. When I click one of the rows, I want to view details from another bean list what would I write to value to second detail datatable list ?
Let say I have a bean of list students datatable containing name, surname and numbers, when I click a row, on the second datatable there is a bean list of student's address, city and country
Now I can System.out.print the adress detail of student when I click to row in student table but I can't show it on datatable
I'm asking how I can take the values to a datatable, what will be the value in datatable?
Thanks for your help
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<h:head></h:head>
<h:body>
<f:view>
<h:form id="form">
<p:dataTable id="users" var="user" value="#{userOS.osList}"
paginator="true" rows="10" rowKey="#{user.kisiid}"
selection="#{userOS.selectedOS}" selectionMode="single">
<f:facet name="header">
Kullanıcı detaylarını görmek için view butonuna tıklayınız
</f:facet>
<p:ajax event="rowSelect" listener="#{userOS.onRowSelect}" update=":form:display"
oncomplete="userDialog" />
<p:column headerText="Student No" sortBy="ogrencino"
filterBy="ogrencino" id="ogrencino">
<h:outputText value="#{user.ogrencino}" />
<f:param name="kid" value="#{userOS.osList.rowIndex}" />
</p:column>
<p:column headerText="Name" sortBy="ad" filterBy="ad" id="ad">
<h:outputText value="#{user.ad}" />
</p:column>
<p:column headerText="Surname" sortBy="soyad" filterBy="soyad"
id="soyad">
<h:outputText value="#{user.soyad}" />
</p:column>
<p:column headerText="Faculty" sortBy="altbirim.ad"
filterBy="altbirim.ad" id="altbirim">
<h:outputText value="#{user.altbirim.ad}" />
</p:column>
<p:column headerText="Department" sortBy="bolum.ad"
filterBy="bolum.ad" id="bolum">
<h:outputText value="#{user.bolum.ad}" />
</p:column>
<p:column headerText="Status" sortBy="ogrencidurum.ad"
filterBy="ogrencidurum.ad" id="ogrencidurum">
<h:outputText value="#{user.ogrencidurum.ad}" />
</p:column>
<f:facet name="footer">
</f:facet>
</p:dataTable>
<p:panel id="dialog" header="User Detail" widgetVar="userDialog">
<h:panelGrid id="panelgrid" columns="2" cellpadding="4">
<p:dataTable id="display" var="adres" value="#{userOS.adresList}">
<p:column headerText="Adres Tipi">
<h:outputText value="#{adres.AddressType}" />
</p:column>
<p:column headerText="Adres">
<h:outputText value="#{adres.Address}" />
</p:column>
<p:column headerText="İl">
<h:outputText value="#{adres.City}" />
</p:column>
<p:column headerText="Ülke">
<h:outputText value="#{adres.Country}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</p:panel>
</h:form>
</f:view>
</h:body>
</html>
And KisiInfoProcess.java code :
package com.revir.process;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.primefaces.event.SelectEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.revir.managed.bean.AddressBean;
import com.revir.managed.bean.OgrenimSureciBean;
import com.revir.domain.Adres;
import com.revir.domain.AdresDAO;
import com.revir.domain.Kisi;
import com.revir.domain.KisiDAO;
import com.revir.domain.Kisiadresi;
import com.revir.domain.Ogrenimsureci;
import com.revir.domain.OgrenimsureciDAO;
import com.revir.domain.Ulke;
import com.revir.process.KisiInfoProcess;
#ManagedBean(name = "userOS")
#SessionScoped
public class KisiInfoProcess implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory
.getLogger(KisiInfoProcess.class);
private List<OgrenimSureciBean> osList;
private List<AddressBean> adresList;
private List<AddressBean> adresListesi;
public List<AddressBean> getAdresListesi() {
return adresListesi;
}
public void setAdresListesi(List<AddressBean> adresListesi) {
this.adresListesi = adresListesi;
}
private OgrenimSureciBean selectedOS;
private AddressBean selectedAdres;
public OgrenimSureciBean getSelectedOS() {
return selectedOS;
}
public void setSelectedOS(OgrenimSureciBean selectedOS) {
this.selectedOS = selectedOS;
}
public AddressBean getSelectedAdres() {
return selectedAdres;
}
public void setSelectedAdres(AddressBean selectedAdres) {
this.selectedAdres = selectedAdres;
}
public List<OgrenimSureciBean> getOsList() {
OgrenimsureciDAO ogrenimsureciDAO = new OgrenimsureciDAO();
List<OgrenimSureciBean> osList = new ArrayList<OgrenimSureciBean>();
for (Iterator i = ogrenimsureciDAO.findByMezunOgrenciler((short) 8)
.iterator(); i.hasNext();) {
Ogrenimsureci og = (Ogrenimsureci) i.next();
OgrenimSureciBean osBean = new OgrenimSureciBean();
osBean.setBolum(og.getBolum());
osBean.setAd(og.getKisiByKisiid().getAd());
osBean.setSoyad(og.getKisiByKisiid().getSoyad());
osBean.setAltbirim(og.getAltbirim());
osBean.setOgrencino(og.getOgrencino());
osBean.setKisiid(og.getKisiByKisiid().getKisiid());
osBean.setOgrencidurum(og.getOgrencidurum());
osList.add(osBean);
System.out.println("osBean : " + osBean.toString());
}
return osList;
}
public void setOsList(List<OgrenimSureciBean> osList) {
this.osList = osList;
}
public void onRowSelect(SelectEvent event) {
System.out.println("On Row Select Metodu çalıştı");
try {
getAdresList();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<AddressBean> getAdresList() throws Exception {
if (getSelectedOS() != null) {
log.debug("PersonalInfoProcess - getAddressInfo - Start");
List<AddressBean> adresList = new ArrayList<AddressBean>();
KisiDAO kisiDAO = new KisiDAO();
AdresDAO adresDAO = new AdresDAO();
Long kisiid = getSelectedOS().getKisiid();
System.out.println("kisiid :" + kisiid);
Kisi kisi = kisiDAO.findById(kisiid);
for (Iterator i = kisi.getKisiadresis().iterator(); i.hasNext();) {
Kisiadresi kisiAdresi = (Kisiadresi) i.next();
System.out.println("i :" + i);
Adres tmpAdres = adresDAO.findById(kisiAdresi.getId()
.getAdresid());
if (tmpAdres != null) {
AddressBean address = new AddressBean(kisiid);
if (tmpAdres.getAdresturu() == null) {
address.setAddressType(null);
} else {
address.setAddressType(tmpAdres.getAdresturu().getAd());
System.out.println("Adres Türü:" +tmpAdres.getAdresturu().getAd());
}
address.setAddress(tmpAdres.getAdres());
System.out.println("Şehir:" +tmpAdres.getAdres());
if (tmpAdres.getIl() == null) {
address.setCity(null);
} else {
address.setCity(tmpAdres.getIl().getAd());
System.out.println("Şehir:" +tmpAdres.getIl().getAd());
}
if (tmpAdres.getUlke() == null) {
address.setCountry(null);
} else {
address.setCountry(tmpAdres.getUlke().getAd());
System.out.println("Ülke:" +tmpAdres.getUlke().getAd());
}
adresList.add(address);
System.out.println("adres" + address);
System.out.println("adreslist" + adresList);
}
log.debug("PersonalInfoProcess - getAddressInfo - End / Returning");
}
}
return adresList;
}
public void setAdresList(List<AddressBean> adresList) {
this.adresList = adresList;
}
}
initiate.xhtml
I am using the primefaces wizard to show the sequential flow for an application.In one of the tab namely member details, I have an editable data table .For the Name column,I want the user to select the name from the available list of users having Name,designation,division on clicking a button
I am using another datatable in the dialog box on clicking on a button.
But how can i update the selected value in the original data table after clicking on add button.
<h:body>
<h:form id="compositionmaster">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard widgetVar="wiz" flowListener="#{userWizard.onFlowProcess}" step="address" >
<p:tab id="address" title="Member Details">
<p:panel header="Member Selection" >
<h:messages errorClass="error"/>
<p:dataTable id="outputtable" var="membertable" value="#{tableBean.compositionRoles}" editable="true" editMode="cell" >
<p:column headerText="Role" >
<h:outputText value="#{membertable.role}" />
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="input">
<p:selectOneMenu value="#{userWizard.user.type}">
<f:selectItem itemLabel="--Select--" itemValue="0" />
<f:selectItem itemLabel="Internal" itemValue="1" />
<f:selectItem itemLabel="External" itemValue="2" />
</p:selectOneMenu>
</f:facet>
<f:facet name="output">
<h:outputText value="#{userWizard.user.type}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column id="namecol" headerText="Name">
<p:commandButton id="basic" value="..." onclick="dlg.show();" type="button" />
<h:outputText value="#{userBean.selectedUser.name}" />
</p:column>
<p:column id="divcol" headerText="Section/Division">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{userBean.selectedUser.division}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{userBean.selectedUser.division}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<p:dialog id="dialog" header="UserList" widgetVar="dlg" >
<h:form id="userform">
<p:dataTable var="user" value="#{userBean.users}" selection="#{userBean.selectedUser}" rowKey="#{user.name}" >
<p:column selectionMode="single"/>
<p:column headerText="Name">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="Division">
<h:outputText value="#{user.division}" />
</p:column>
<f:facet name="footer">
<p:commandButton update=":compositionmaster:namecol" ajax="true" onclick="dlg.hide()" value="Add" id="addmember"/>
</f:facet>
</p:dataTable>
</h:form>
</p:dialog>
UserWizard.java
package committee;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ActionEvent;
import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import org.primefaces.event.FlowEvent;
import java.io.Serializable;
import javax.faces.bean.ViewScoped;
import office.UserBean;
#ManagedBean
#ViewScoped
public class UserWizard implements Serializable{
private User user = new User();
private Committee comm =new Committee();
private boolean skip;
private UserBean userbean;
private static final Logger logger = Logger.getLogger(UserWizard.class.getName());
public UserBean getUserbean() {
return userbean;
}
public void setUserbean(UserBean userbean) {
this.userbean = userbean;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Committee getComm() {
return comm;
}
public void setComm(Committee comm) {
this.comm = comm;
}
public void save(ActionEvent actionEvent) {
//Persist user
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public String onFlowProcess(FlowEvent event) {
System.out.println(event.getOldStep());
System.out.println(event.getNewStep());
System.out.println(skip);
logger.log(Level.INFO, "Current wizard step:{0}", event.getOldStep());
logger.log(Level.INFO, "Next step:{0}", event.getNewStep());
return event.getNewStep();
}
}
UserBean.java
package office;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import committee.User;
import committee.UserDataModel;
import java.util.List;
import java.util.ArrayList;
#ManagedBean
#ViewScoped
public class UserBean implements Serializable{
private List<User> users;
public UserBean() {
users = new ArrayList<User>();
users.add(new User("Kanika","Development"));
users.add(new User("Shreya","Development"));
users.add(new User("Tushti","Development"));
users.add(new User("abc","Marketing"));
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
private User selectedUser;
private UserDataModel userDataModel;
public UserDataModel getUserDataModel() {
return userDataModel;
}
public void setUserDataModel(UserDataModel userDataModel) {
this.userDataModel = userDataModel;
}
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
}