<p:dataTable>'s onExpandStart attribute is not working - java

In my application I want to execute a client side method before expanding row of <p:dataTable> so I am using onExpandStart="alert('Helo');". But this also is not working for me.
.xhtml code snippet :
<p:dataTable value="#{ExampleDataModel}" lazy="true" paginator="true" onExpandStart="alert('Helo');">
<p:column id="rowToggle" styleClass="rowtoggle">
<p:rowToggler />
</p:column>
<p:rowExpansion>
..........
</p:rowExpansion>
</p:dataTable>
can anyone tell wher I have done wrong? I am using PF 3.4,Mojara(2). Thanks.
Update-1 :
managedBean's code snippet :
#ManagedBean(name = "columnController")
#ViewScoped
public class ColumnController implements Serializable {
private List<ColumnDTO> userNames;
public List<ColumnDTO> getUserNames() {
List<ColumnDTO> columns = new ArrayList<ColumnDTO>();
columns.add(new ColumnDTO(Integer.valueOf(1), "Diganta"));
columns.add(new ColumnDTO(Integer.valueOf(2), "Jayanta"));
columns.add(new ColumnDTO(Integer.valueOf(3), "Proloy"));
return columns;
}
public void setUserNames(List<ColumnDTO> userNames) {
this.userNames = userNames;
}
}
ColumnDTO.java :
public class ColumnDTO implements Serializable {
private static final long serialVersionUID = 4828438441215128064L;
private Integer columnId;
private String columnName;
public ColumnDTO(Integer index, String columnName) {
this.columnId = index;
this.columnName = columnName;
}
//...........getter setter
}
.xhtml code :
<h:head></h:head>
<body>
<h:form>
<p:dataTable value="#{columnController.userNames}" var="name" onExpandStart="alert('Hello')">
<p:column>
<p:rowToggler/>
</p:column>
<p:column>
<h:outputText value="#{name.columnName}" />
</p:column>
<p:rowExpansion>
<h:outputText value="#{name.columnId}" />
</p:rowExpansion>
</p:dataTable>
</h:form>
</body>
</html>

Try <p:ajax event="rowToggle" onstart="alert('Helo');"/> instead of onExpandStart

Related

'Show All' button for Primefaces DataTable

I would like to have a 'Show All' button for a primefaces datatable, however, I'm experiencing some trouble. Here's some test code that demostrates the problem:
Test.xhtml:
...
<h:form>
<p:selectBooleanCheckbox value="#{testBean.showAll}" itemLabel="Show All">
<p:ajax update="#form"/>
</p:selectBooleanCheckbox>
<p:panel id="test">
<p:dataTable id="values" var="value" value="#{testBean.fullList}" filteredValue="#{testBean.filteredList}" paginatorAlwaysVisible="false"
paginator="#{!testBean.showAll}" rows="#{!testBean.showAll ? 2 : null }" widgetVar="valuesTable"
emptyMessage="No records found.">
<p:column id="enum" sortBy="#{value.toString()}" filterBy="#{value.toString()}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Enum" />
</f:facet>
<h:outputText value ="#{value.toString()}"/>
</p:column>
<p:column id="name" sortBy="#{value.name}" filterBy="#{value.name}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{value.name}" />
</p:column>
</p:dataTable>
</p:panel>
</h:form>
...
And here's TestBean.java:
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
#Named(value = "testBean")
#SessionScoped
public class TestBean implements Serializable {
public static enum Value {
ONE, TWO, THREE;
public String getName() {
return name().toLowerCase();
}
#Override
public String toString() {
return this.name();
}
}
/**
* Creates a new instance of TestBean
*/
public TestBean() {
}
private boolean showAll = false;
private List<Value> fullList = Arrays.asList(Value.values());
private List<Value> filteredList;
public boolean isShowAll() {
return showAll;
}
public void setShowAll(boolean showAll) {
this.showAll = showAll;
}
public List<Value> getFullList() {
return fullList;
}
public void setFullList(List<Value> fullList) {
this.fullList = fullList;
}
public List<Value> getFilteredList() {
return filteredList;
}
public void setFilteredList(List<Value> filteredList) {
this.filteredList = filteredList;
}
}
If I don't change tabs, the page works as expected: toggling the 'Show All' button updates the table to show all 3 values, or only two. However, if show all is not checked (only 2 rows are showing), and I click to the 2nd page of the table to view the third record, and then click 'Show All', the table does not update properly. It removes the paginator from the top of the table (as expected), but still only shows the 3rd record. And if I then uncheck show all and navigate back to the first page of the datatable, it is now broken too.
I've tried changing the ajax update statement to the id of the table, but that didn't change the results.
Am I doing something wrong? Thanks in advance.
You have to programmatically set the values you need directly on the DataTable component (I used explicit first and rows bean properties just for more readability):
<h:form>
<p:selectBooleanCheckbox value="#{testBean.showAll}" itemLabel="Show All">
<p:ajax update="#form" />
</p:selectBooleanCheckbox>
<p:panel id="test">
<p:dataTable id="values" var="value" value="#{testBean.fullList}"
filteredValue="#{testBean.filteredList}" paginatorAlwaysVisible="false"
paginator="#{!testBean.showAll}" first="#{testBean.first}" rows="#{testBean.rows}"
widgetVar="valuesTable" emptyMessage="No records found.">
<p:column id="enum" sortBy="#{value.toString()}" filterBy="#{value.toString()}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Enum" />
</f:facet>
<h:outputText value="#{value.toString()}" />
</p:column>
<p:column id="name" sortBy="#{value.name}" filterBy="#{value.name}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{value.name}" />
</p:column>
</p:dataTable>
</p:panel>
</h:form>
and
#Named
#ViewScoped
public class TestBean implements Serializable
{
private static final long serialVersionUID = 1L;
public static enum Value
{
ONE, TWO, THREE;
public String getName()
{
return name().toLowerCase();
}
#Override
public String toString()
{
return name();
}
}
private boolean showAll = false;
private int first = 0;
private int rows = 2;
private List<Value> fullList = Arrays.asList(Value.values());
private List<Value> filteredList;
public boolean isShowAll()
{
return showAll;
}
public void setShowAll(boolean showAll)
{
this.showAll = showAll;
first = 0;
rows = showAll ? 0 : 2;
filteredList = null;
// get the FacesContext instance
FacesContext context = FacesContext.getCurrentInstance();
// get the current component (p:selectBooleanCheckbox)
UIComponent component = UIComponent.getCurrentComponent(context);
// find DataTable within the same NamingContainer
DataTable table = (DataTable) component.findComponent("values");
// reset first row index
table.setFirst(first);
// reset last row index
table.setRows(rows);
// reset filterd value
table.setFilteredValue(null);
}
// all other getters/setters
}
Tested on Wildfly 10.0.0.Final with JSF 2.3.0-m06 (Mojarra) and PrimeFaces 6.0.2
I had the same problem, was resolved by this steps:
Adding styleClass="all-paginator" to datatable
<p:dataTable id="values" var="value" value="#{testBean.fullList}"
filteredValue="#{testBean.filteredList}" styleClass="all-paginator"..>
Add a getter of number of all records in the controller (TestBean.java) like:
public int getRecordNumber() {
if(CollectionUtils.isEmpty(fullList)){
return 0;
}
return fullList.size();
}
Add the property of the recordNumber at the end of the datatable attribute "rowsPerPageTemplate"
<p:dataTable id="values" var="value" value="#{testBean.fullList}" filteredValue="#{testBean.filteredList}"
styleClass="all-paginator" rowsPerPageTemplate="20,30,40,50,#{testBean.recordNumber}"..>

Primefaces SelectCheckboxMenu null value

I'm trying to get selected values from a selectCheckboxMenu, but all I'm getting is null in the console. It doesn't work with selectOneMenu too. Here's my jsf form:
<h:form id="mmaster">
<p:dataTable
value="#{devicesBean.devices}"
var="dev"
widgetVar="dt"
border="1"
paginator="true"
paginatorPosition="top"
rows="10"
>
<f:facet name="header">Devices</f:facet>
<p:column headerText="UDN" sortBy="#{dev.deviceUDN}" filterBy="#{dev.deviceUDN}" filterMatchMode="contains" emptyMessage="No Devices Found">
<h:outputText value="#{dev.deviceUDN}" />
</p:column>
<p:column headerText="FriendlyName" sortBy="#{dev.deviceFriendlyName}" filterBy="#{dev.deviceFriendlyName}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceFriendlyName}" />
</p:column>
<p:column headerText="Model" sortBy="#{dev.deviceModel}" filterBy="#{dev.deviceModel}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceModel}" />
</p:column>
<p:column headerText="Manufacturer" sortBy="#{dev.deviceManufacturer}" filterBy="#{dev.deviceManufacturer}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceManufacturer}" />
</p:column>
<p:column headerText="Type" sortBy="#{dev.deviceType}" filterBy="#{dev.deviceType}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceType}" />
</p:column>
<p:column headerText="Actions">
<p:selectCheckboxMenu value="#{devicesBean.selectAnnotations}">
<f:selectItems value="#{devicesBean.annotations}" />
</p:selectCheckboxMenu>
</p:column>
<p:column>
<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="#this">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
I wonder if there is a problem in the bean's scope, And this is my managed bean:
#ManagedBean
public class DevicesBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<Device> devices;
private List<String> annotations;
private List<String> selectAnnotations = new ArrayList<String>();
private Device device;
#EJB
IOntoProcessor iop;
#EJB
IDevicesDao idd;
public DevicesBean() {
}
#PostConstruct
public void init() {
setDevices(idd.getAllDevices());
setAnnotations(iop.getAllAnnotations());
}
public List<Device> getDevices() {
return devices;
}
public void setDevices(List<Device> devices) {
this.devices = devices;
}
public List<String> getAnnotations() {
return annotations;
}
public void setAnnotations(List<String> annotations) {
this.annotations = annotations;
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public List<String> getSelectAnnotations() {
return selectAnnotations;
}
public void setSelectAnnotations(List<String> selectAnnotations) {
this.selectAnnotations = selectAnnotations;
}
public void doSave() {
System.out.println(selectAnnotations);
System.out.println(device);
selectAnnotations = new ArrayList<String>();
}
}
You are trying to submit the form through the Button with value Annotate, which has been specified to process itself only:
This will only process the button and its associated form parameters, and no other element within the form.
<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="#this">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>
Either remove the process="#this", or replace it with process="#form"
<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="#form">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>
Two, declare your managed bean scope: Either #RequestScope or #SessionScoped will work fine.

deleting a row in integration of jsf spring hibernate primefaces

i am using integration of jsf hibernate spring primfaces in my project. i want to delete row in my primefaces data table. but i am not sure about delete method in my managed bean. when i want to delete i have following error. please help me to write correct deletePersonel method.
/personel.xhtml #95,74 actionListener="#{personelMB.deletePersonel()}": java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Personel.java
#Entity
#Table(name="TBLPERSONEL")
public class Personel {
#Id
#Column(name="PERSONEL_ID")
private int personel_id;
#Column(name="PNAME")
private String pname;
#Column(name="PFAMILY")
private String pfamily;
#Column(name="PADDRESS")
private String paddress;
#Column(name="PPHONE")
private String pphone;
#OneToOne
#PrimaryKeyJoinColumn
private Manager manager;
#OneToMany(mappedBy="personel")
private Set<Stufftransfer> stufftransfers;
public Personel(){
}
//getter and setter
PersonelDao
public class PersonelDao implements IPersonelDao {
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void deletePersonel(Personel personel) {
getSessionFactory().getCurrentSession().delete(personel);
}
PersonelService
#Transactional(readOnly=true)
public class PersonelService implements IPersonelService{
IPersonelDao personeldao;
public IPersonelDao getPersoneldao() {
return personeldao;
}
public void setPersoneldao(IPersonelDao personeldao) {
this.personeldao = personeldao;
}
#Transactional(readOnly=false)
#Override
public void deletePersonel(Personel personel) {
getPersoneldao().deletePersonel(personel);
}
PersonelBean
#ManagedBean(name="personelMB")
#SessionScoped
public class PersonelBean implements Serializable{
private static final long serialVersionUID = 1L;
#ManagedProperty(value="#{PersonelService}")
IPersonelService personelservice;
List<Personel> personelList;
private int personel_id;
private String pname;
private String pfamily;
private String paddress;
private String pphone;
public IPersonelService getPersonelservice() {
return personelservice;
}
public void setPersonelservice(IPersonelService personelservice) {
this.personelservice = personelservice;
}
public List<Personel> getPersonelList() {
personelList=new ArrayList<Personel>();
personelList.addAll(getPersonelservice().getPersonels());
return personelList;
}
public void setPersonelList(List<Personel> personelList) {
this.personelList = personelList;
}
public void addPersonel(){
Personel personel=new Personel();
personel.setPaddress(getPaddress());
personel.setPersonel_id(getPersonel_id());
personel.setPfamily(getPfamily());
personel.setPname(getPname());
personel.setPphone(getPphone());
getPersonelservice().addPersonel(personel);
}
public void deletePersonel(){
Personel personel=(Personel)personelservice.getPersonelId(personel_id);
getPersonelservice().deletePersonel(personel);
}
//getter and setter
personel.xhtml
<?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 dir="rtl"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>اطلاعات پرسنلی</title>
</h:head>
<h:body>
<h1>اضافه کردن پرسنل جدید</h1>
<h:form>
<h:panelGrid columns="4" >
شماره پرسنلی :
<h:inputText id="id" value="#{personelMB.personel_id}"
size="20" required="true"
label="id" >
</h:inputText>
<br></br>
نام :
<h:inputText id="name" value="#{personelMB.pname}"
size="20" required="true"
label="Name" >
</h:inputText>
نام خانوادگی:
<h:inputText id="family" value="#{personelMB.pfamily}"
size="20" required="true"
label="family" >
</h:inputText>
آدرس :
<h:inputTextarea id="address" value="#{personelMB.paddress}"
cols="30" rows="10" required="true"
label="Address" >
</h:inputTextarea>
تلفن:
<h:inputText id="tel" value="#{personelMB.pphone}"
size="20" required="true"
label="tel" >
</h:inputText>
</h:panelGrid>
<h:commandButton value="درج اطلاعات" action="#{personelMB.addPersonel()}" />
</h:form>
<h2>مشاهده اطلاعات پرسنل</h2>
<h:form prependId="false">
<p:dataTable id="dataTable" var="personel" value="#{personelMB.personelList}" rowKey="#{personelMB.personel_id}">
<f:facet name="header">
اطلاعات پرسنل
</f:facet>
<p:column>
<f:facet name="header">
شماره پرسنلی
</f:facet>
<h:outputText value="#{personel.personel_id}" />
<f:facet name="footer">
کدملی
</f:facet>
</p:column>
<p:column headerText="نام">
<h:outputText value="#{personel.pname}" />
</p:column>
<p:column headerText="نام خانوادگی">
<h:outputText value="#{personel.pfamily}" />
</p:column>
<p:column headerText="آدرس">
<h:outputText value="#{personel.paddress}" />
</p:column>
<p:column headerText="تلفن">
<h:outputText value="#{personel.pphone}" />
</p:column>
<p:column>
<f:facet name="حذف">
<h:outputText value="" />
</f:facet>
<p:commandButton icon="ui-icon-close" title="حذف"
actionListener="#{personelMB.deletePersonel()}" />
</p:column>
<f:facet name="footer">
تعداد رکورد#{fn:length(personelMB.getPersonelList())} میباشد.
</f:facet>
</p:dataTable>
</h:form>
</h:body>
</html>
please help me to write correct deletePersonel in my PersonelBean.java.
Change your managed bean delete method likes this;
public void deletePersonel(int personel_id){
Personel personel=(Personel)personelservice.getPersonelId(personel_id);
getPersonelservice().deletePersonel(personel);
}
and also change your xhtml likes this;
<p:commandButton icon="ui-icon-close" title="حذف"
actionListener="#{personelMB.deletePersonel(personel.personel_id)}" />
Add refresh method to your managed bean likes this;
public String deleteAction(Personel personel) {
personelList.remove(personel);
return null;
}
and edit your p:commandButton likes this;
<p:commandButton icon="ui-icon-close" title="حذف"
actionListener="#{personelMB.deletePersonel(personel.personel_id)" action="#{personelMB.delectAction(personel)}"/>

Row selection with multiple p:dataTable

In the following scenario, where I have several dataTables that I build iterating over a ui:repeat tag, I have experienced that row listener returns null for selected elements that are not in the first table.
In order to understand the model object, I have several menus, and each of them contains several areas.
Any help will be much appreciated.
xhtml below:
<ui:repeat value="#{someBean.menus}" var="menu">
<p:dataTable var="area" value="#{menu.areas}"
rowKey="#{area.id}" selection="#{menu.area}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{someBean.rowSelected}" />
<f:facet name="header">#{menu.name}</f:facet>
<p:column>
<f:facet name="header"></f:facet>
<h:outputText value="#{area.id}" />
</p:column>
<p:column>
<f:facet name="header">Area name</f:facet>
<h:outputText value="#{area.name}" />
</p:column>
</p:dataTable>
</ui:repeat>
ListDataModel java implementation:
public class Areas extends ListDataModel<Area> implements SelectableDataModel<Area>, Serializable {
private static final long serialVersionUID = -9102592194300556930L;
public Areas() {
}
public Areas(List<Area> data) {
super(data);
}
#Override
public Area getRowData(String rowKey) {
#SuppressWarnings("unchecked")
List<Area> areas = (List<Area>)getWrappedData();
for (Area area : areas) {
if (String.valueOf(area.getId()).equals(rowKey)) {
return area;
}
}
return null;
}
#Override
public Object getRowKey(Area area) {
return area.getId();
}
}
public class Menus extends ListDataModel<Menu> implements SelectableDataModel<Menu>, Serializable {
private static final long serialVersionUID = -4079772686830676202L;
public Menus() {
}
public Menus(List<Menu> data) {
super(data);
}
#Override
public Menu getRowData(String rowKey) {
#SuppressWarnings("unchecked")
List<Menu> menus = (List<Menu>)getWrappedData();
for (Menu menu : menus) {
if (String.valueOf(menu.getId()).equals(rowKey)) {
return menu;
}
}
return null;
}
#Override
public Object getRowKey(Menu menu) {
return menu.getId();
}
}
...in the bean someBean
public void rowSelected(SelectEvent event) {
Area selectedArea = (Area)event.getObject(); //This, is null for other tables except the first
System.out.println("SELECTED AREA:" + selectedArea);
//...
}
I am glad to show you the solution: replace ui:repeat with another p:dataTable !!!
<p:dataTable value="#{someBean.menus}" var="menu">
<p:column>
<p:dataTable var="area" value="#{menu.areas}"
rowKey="#{area.id}" selection="#{menu.area}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{someBean.rowSelected}" />
<f:facet name="header">#{menu.name}</f:facet>
<p:column>
<f:facet name="header"></f:facet>
<h:outputText value="#{area.id}" />
</p:column>
<p:column>
<f:facet name="header">Area name</f:facet>
<h:outputText value="#{area.name}" />
</p:column>
</p:dataTable>
</column>
</p:dataTable>

Why this table In-Cell editor, doesnt work?

I am trying to figure out, how the primefaces in-cell editor works.
For some reason, it does not work. I just see it activating and also i can type, but the values do not change. What is missing?
<?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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:form>
<p:dataTable id="allSubjects" var="subject" value="#{subjectControllerUpdate.retrieve()}" paginator="true" rows="7" >
<p:column headerText="Name" sortBy="#{subject.name}" style="width:200px" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{subject.name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{subject.name}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{subject.description}" headerText="Description">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{subject.description}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{subject.description}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{subject.credits}" headerText="Credits" style="width:50px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{subject.credits}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{subject.credits}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
</html>
This is the managed bean
package controllers;
import crudfacades.SubjectFacade;
import entities.Subject;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
#Named("subjectControllerUpdate")
#SessionScoped
public class SubjectControllerUpdate implements Serializable {
private List<Subject> subjects;
private Subject currentSubject;
#EJB
private SubjectFacade ejbFacade;
//INITIALIZATION
public SubjectControllerUpdate() {
currentSubject = new Subject();
}
//RETRIEVE
public List<Subject> retrieve() {
return getSubjectFacade().findAll();
}
//UPDATE
//HELP METHODS
//RETURN THE FACADE FOR DATA MANIPULATION(Best practice)
private SubjectFacade getSubjectFacade() {
return ejbFacade;
}
//GETTERS AND SETTERS
public Subject getCurrentSubject() {
return currentSubject;
}
public void setCurrentSubject(Subject currentSubject) {
this.currentSubject = currentSubject;
}
public List<Subject> getSubjects() {
return subjects;
}
public void setSubjects(List<Subject> subjects) {
this.subjects = subjects;
}
}
but when i click comfirm, the value in the UI is not changed
You've bound the value of the <p:dataTable> to retrieve() instead of getSubjects(). So every single getter call will get the values straight from the DB instead of the model.
and i see no changes in the database
You are not saving anything in the DB.
Fix your controller as follows:
#Named
#SessionScoped
public class SubjectControllerUpdate implements Serializable {
private DataModel<Subject> subjects;
#EJB
private SubjectFacade ejbFacade;
#PostConstruct
public void init() {
subjects = new ListDataModel<Subject>(ejbFacade.findAll());
}
public void save() {
ejbFacade.save(subjects.getRowData());
}
public List<Subject> getSubjects() {
return subjects;
}
}
with
<h:form>
<p:dataTable value="#{subjectControllerUpdate.subjects}" ...>
        <p:ajax event="rowEdit" listener="#{subjectControllerUpdate.save}" />
...
</p:dataTable>
</h:form>
Using DataModel<Subject> instead of List<Subject> is necessary in order to be able to get the current row.

Categories

Resources