Primefaces datatable LazyDataModel create new row - jsf

I have a primefaces datatable which uses LazyDataModel instead Collection.
I need to implement a button which create a new row in the table (empty row in last row of actual page in datatable).
I have tried adding.
#Component("table")
#Scope("session")
public class TablaPaginada implements Serializable {
private LazyDataModel<User> users;
#PostConstruct
private void init() {
usuarios = new LazyDataModel<User>() {
private static final long serialVersionUID = 8885722005055879976L;
#Override
public List<User> load(int first, int pageSize, String sortField,
SortOrder sortOrder, Map<String, Object> filters) {
List<User> data = getUsers(first, pageSize, sortOrder, filters);
return data;
}
};
users.setRowCount(totalRowUsers());
}
public void newRow() {
//I would do this if it was List instead LazyDataModel
//this.users.add(new User());
users.getWrappedData().add(new User()); //this does not work.
}
}
This would be the xhtml code:
<h:form>
<p:dataTable rowsPerPageTemplate="5,10,15" value="#{table.users}" var="user" paginator="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rows="5" lazy="true">
<p:column headerText="id" sortBy="#{user.id}" filterBy="#{user.id}">
<h:outputText value="#{user.id}" />
</p:column>
<p:column headerText="name" sortBy="#{user.name}" filterBy="#{user.name}">
<h:outputText value="#{user.name}" />
</p:column>
<p:column headerText="lastName" sortBy="#{user.lastName}" filterBy="#{user.lastName}">
<h:outputText value="#{user.lastName}" />
</p:column>
<p:column headerText="money" sortBy="#{user.money}" filterBy="#{user.money}">
<h:outputText value="#{user.money}" />
</p:column>
</p:dataTable>
<p:commandButton value="new row" action="#{table.newRow()}" update="#form"/>
</h:form>
EDIT:
my code does not create new row.

From PF documentation: <p:commandButton value="Add" actionListener="#{dtBasicView.addCar}"
oncomplete="PF('dt').addRow()" process="#this"/>
And for Lazy Datatable you may run into this issue which has a workaround: https://github.com/primefaces/primefaces/issues/3901

Related

onRowSelect update second lazy p:datatable with new data

I hope someone will give me some hint about my problem. I have two <p:dataTable> that have lazy load. On first <p:dataTable> user can select row. According to selected row second <p:dataTable> must be updated with new lazy data (lazyModel2).
I don't know how to get new lazyModel2 and update second <p:dataTable> with new data on row select. onRowSelect event is working and I can get selectedRow data.
I just don't have any idea how to get new lazyModel2 from onRowSelect() method.
XHTML
<p:dataTable id="dt1"
var="dtVar1"
value="#{controller.lazyModel1}"
lazy="true"
rowKey="#{dtVar1.recordId}"
filterEvent="enter"
sortMode="multiple"
selectionMode="single"
selection="#{controller.selected1item}">
<p:ajax event="rowSelect"listener="#{controller.onRowSelect}"update="MasterForm:dt2"/>
<p:column headerText="Text" sortBy="#{dtVar1.text}" filterBy="#{dtVar1.text}" style="width: 100px">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{dtVar1.text}"/></f:facet>
<f:facet name="input"><p:inputText value="#{dtVar1.text}"style="width: 100%"/></f:facet>
</p:cellEditor>
</p:column>
...
</p:dataTable>
<p:dataTable id="dt2"
var="dtVar2"
value="#{controller.lazyModel2}"
lazy="true"
rowKey="#{dtVar2.recordId}"
filterEvent="enter"
sortMode="multiple"
editable="true"
editMode="row">
<p:ajax event="rowEdit" listener="#{controller.onRowEdit}" update="dt2"/>
<p:column style="width: 32px">
<f:facet name="header"><h:outputText value=""/></f:facet>
<p:rowEditor/>
</p:column>
<p:column headerText="Text 2" sortBy="#{dtVar2.konto}" filterBy="#{dtVar2.konto}" style="width: 100px">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{dtVar2.konto}"/></f:facet>
<f:facet name="input"><p:inputText value="#{dtVar2.konto}" style="width: 100%"/></f:facet>
</p:cellEditor>
</p:column>
...
</p:dataTable>
CONTROLLER
#Named
#ViewScoped
public class Controller extends GenericWebController {
#Inject
private Lazy1DataModel lazyModel1;
#Inject
private Lazy2DataModel lazyModel2;
public void onRowSelect(SelectEvent event) throws SQLException {
...
filters.put("recordId", arraylistafiltera);
...
List<FPromInDto> newlazy = getLazyModel2().load(0,15,null, filters);
lazyModel2.setWrappedData(newlazy);
}
public Lazy1DataModel getLazyModel1() { return lazyModel1; }
public void setLazyModel1(Lazy1DataModel lazyModel1) { this.lazyModel1 = lazyModel1; }
public Lazy2DataModel getLazyModel2() { return lazyModel2; }
public void setLazyModel2(Lazy2DataModel lazyModel2) { this.lazyModel2 = lazyModel2; }
}
Lazy2DataModel
public class Lazy2DataModel extends LazyDataModel<SomeDto> {
#Inject
private SomeDao someDao;
#Override
public List<SomeDto> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String, Object> filters) {
List<SomeDto> data = new ArrayList<>();
try {
data = someDao.lazyLoad(first, pageSize, BiLazyUtils.getSortString(multiSortMeta, SomeDto.class), BiLazyUtils.getFilterString(filters, SomeDto.class));
this.setRowCount(someDao.count(BiLazyUtils.getFilterString(filters, SomeDto.class)));
} catch (SQLException e) {
e.printStackTrace();
}
return data;
}

#ViewScoped is recreated after button action on WebLogic

First of all I know some other similar questions about my title, but My issue is a little bit different... When I try to initialize LazyDataModel in my #ViewScoped Bean it works fine until I click the actionButton on my page. When My Bean is created, its #PostConstruct method works as expected and LazyDataModel filled up in that method then datatable populated well. But when ajax called by actionButton in my page then entire bean recreated and #PostConstruct method called again, with that LazyDataModel value changing to null. Because of that, my page is crashing. In another scenario I was using rowSelect event in my datatable instead of actionButton with method which has a SelectEvent parameter. In SelectEvent parameter object field of it was null and I was getting NullPointerException. These are the scenarios... As result I guess when I use LazyDataModel in my #ViewScoped bean It calls PostConstruct again and my datamodel returns null for my SelectEvent method.
This is my ViewScoped PostConstruct method
#ManagedBean (name = "myEctrInboxBB")
#ViewScoped
public class MyEContractInboxBackingBean implements Serializable {
private static final long serialVersionUID = 2399679621562918360L;
private static final Logger logger = LogManager.getLogger(MyEContractInboxBackingBean.class);
#ManagedProperty("#{ectrDomainService}")
EContractDomainService ectrDomainService;
#ManagedProperty("#{eContractUtil}")
EContractUtilBean eContractUtil;
#ManagedProperty("#{ectrApproveController}")
EContractApproveControllerBean ectrApproveController;
private EContractInboxItem selectedInboxRow;
private LazyEContractInboxItemModel lazyEcontractInboxItem;
private List<EContractInboxItem> inboxItems = new ArrayList<EContractInboxItem>();
private List<EContractInboxItem> filteredInboxItems = new ArrayList<EContractInboxItem>();
#PostConstruct
public void init() {
User portalUser = getUser();
List<String> userRoles = fetchUserRoles(portalUser);
List<String> userSmCodes = fetchUserSmCodes(userRoles, portalUser);
lazyEcontractInboxItem = new LazyEContractInboxItemModel(ectrDomainService, eContractUtil, userRoles, userSmCodes);
}
public void onRowSelect(SelectEvent selectEvent) {
logger.info("**************************" + selectEvent);
}
public void openSelectedJob(EContractInboxItem item) {
ectrApproveController.openEContractInfoPage(item.getProcessInstanceId());
}
LazyDataModel
public class LazyEContractInboxItemModel extends LazyDataModel<EContractInboxItem>{
List<EContractInboxItem> inboxItems = new ArrayList<EContractInboxItem>();
List<Task> taskList = new ArrayList<Task>();
EContractDomainService ectrDomainService;
EContractUtilBean ectrUtilBean;
List<String> userRoles = new ArrayList<String>();
List<String> userSmCodes = new ArrayList<String>();
public LazyEContractInboxItemModel(EContractDomainService ectrDomainService, EContractUtilBean utilBean, List<String> roles,
List<String> smCodes) {
userRoles.addAll(roles);
userSmCodes.addAll(smCodes);
ectrUtilBean = utilBean;
this.ectrDomainService = ectrDomainService;
}
public List<EContractInboxItem> getInboxItems() {
return inboxItems;
}
public void setInboxItems(List<EContractInboxItem> inboxItems) {
this.inboxItems = inboxItems;
}
#Override
public List<EContractInboxItem> load(int first, int pageSize, String sortField, SortOrder sortOrder,
Map<String, Object> filters) {
taskList = ectrDomainService.findTaskListAssignedToUserByUser(userRoles, userSmCodes);
inboxItems.clear();
inboxItems.addAll(ectrUtilBean.retrieveInboxItems(taskList));
setRowCount(inboxItems.size());
return inboxItems;
}
#Override
public List<EContractInboxItem> load(int first, int pageSize, List<SortMeta> multiSortMeta,
Map<String, Object> filters) {
taskList = ectrDomainService.findTaskListAssignedToUserByUser(userRoles, userSmCodes);
inboxItems.clear();
inboxItems.addAll(ectrUtilBean.retrieveInboxItems(taskList));
setRowCount(inboxItems.size());
return inboxItems;
}
#Override
public Object getRowKey(EContractInboxItem object) {
return object.getProcessInstanceId();
}
#Override
public EContractInboxItem getRowData() {
return super.getRowData();
}
#Override
public EContractInboxItem getRowData(String rowKey) {
for (EContractInboxItem eContractInboxItem : inboxItems) {
if (rowKey.equals(eContractInboxItem.getProcessInstanceId()))
return eContractInboxItem;
}
return null;
}
getters and setters
xhtml page with actionButton
<?xml version="1.0"?>
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:form
id="eContractWaitingApprovalForm"
prependId="false"
enctype="multipart/form-data">
<p:messages id="topmsgForEcontractWaitingApproval" />
<div class="ui-grid ui-grid-responsive">
<p:dataTable
id="waitingEcontracts"
widgetVar="waitingEcontracts"
styleClass="grid-sm-bottom"
rows="20"
resizableColumns="true"
resizeMode="expand"
paginator="true"
lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,50,100,200"
value="#{myEctrInboxBB.lazyEcontractInboxItem}"
var="item">
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.no']}">
<h:outputText value="#{item.eContract.eContractCode}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.subject']}">
<h:outputText value="#{item.eContract.eContractSubject}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.date']}">
<h:outputText value="#{item.eContract.eContractDate}">
<f:convertDateTime
type="date"
pattern="dd-MM-yyyy" />
</h:outputText>
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.name']}">
<h:outputText value="#{item.agencyName}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.type']}">
<h:outputText value="#{item.agencyType}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.sales.manager']}">
<h:outputText
value="#{myEctrInboxBB.findSalesOfficeBySmCode(item.agencySM)}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.status']}">
<h:outputText
value="#{item.eContract.eContractStatus eq 'INPROGRESS' ? i18n['e-contract.dt.waiting.inprogress'] : item.eContract.eContractStatus}" />
</p:column>
<p:column styleClass="center-column">
<p:commandButton
process="#this"
icon="ui-icon-search"
value="#{i18n['e-contract.dt.waiting.see.detail']}"
action="#{myEctrInboxBB.openSelectedJob(item)}" />
</p:column>
</p:dataTable>
</div>
</h:form>
xhtml page with rowSelect
<?xml version="1.0"?>
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:form
id="eContractWaitingApprovalForm"
prependId="false"
enctype="multipart/form-data">
<p:messages id="topmsgForEcontractWaitingApproval" />
<div class="ui-grid ui-grid-responsive">
<p:dataTable
id="waitingEcontracts"
widgetVar="waitingEcontracts"
styleClass="grid-sm-bottom"
rows="20"
resizableColumns="true"
resizeMode="expand"
paginator="true"
lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,50,100,200"
value="#{myEctrInboxBB.lazyEcontractInboxItem}"
var="item"
selection="#{myEctrInboxBB.selectedInboxRow}"
selectionMode="single"
rowKey="#{item.processInstanceId}">
<p:ajax event="rowSelect" listener="#{myEctrInboxBB.onRowSelect}"/>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.no']}">
<h:outputText value="#{item.eContract.eContractCode}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.subject']}">
<h:outputText value="#{item.eContract.eContractSubject}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.date']}">
<h:outputText value="#{item.eContract.eContractDate}">
<f:convertDateTime
type="date"
pattern="dd-MM-yyyy" />
</h:outputText>
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.name']}">
<h:outputText value="#{item.agencyName}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.type']}">
<h:outputText value="#{item.agencyType}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agency.sales.manager']}">
<h:outputText
value="#{myEctrInboxBB.findSalesOfficeBySmCode(item.agencySM)}" />
</p:column>
<p:column
styleClass="center-column"
headerText="#{i18n['e-contract.dt.waiting.agreement.status']}">
<h:outputText
value="#{item.eContract.eContractStatus eq 'INPROGRESS' ? i18n['e-contract.dt.waiting.inprogress'] : item.eContract.eContractStatus}" />
</p:column>
</p:dataTable>
</div>
</h:form>
When I clicked a row of Datatable selectEvent.getObject() --> NULL always with LazyDataModel.
A big important information: These all situations happens in WebLogic 10.3.6.0 and works on TomCat like charm (even with LazyDataModel).
My Development environment: JSF 2.0, Primefaces 5.2, Liferay 6.2.3 ga4 with TomCat 7.04.
Testing environment: Same all except WebLogic 10.3.6.0 (Problem only occurs on here)
I really appreciate if someone could help me... Thanks in advance!!!
EDIT:
#ManagedBean (name = "myEctrInboxBB")
#ViewScoped
public class MyEContractInboxBackingBean implements Serializable {
private static final long serialVersionUID = 2399679621562918360L;
private static final Logger logger = LogManager.getLogger(MyEContractInboxBackingBean.class);
#ManagedProperty("#{ectrDomainService}")
private transient EContractDomainService ectrDomainService;
#ManagedProperty("#{eContractUtil}")
private EContractUtilBean eContractUtil;
#ManagedProperty("#{ectrApproveController}")
private EContractApproveControllerBean ectrApproveController;
private EContractInboxItem selectedInboxRow;
private LazyEContractInboxItemModel lazyEcontractInboxItem;
#PostConstruct
public void init() {
User portalUser = getUser();
List<String> userRoles = fetchUserRoles(portalUser);
List<String> userSmCodes = fetchUserSmCodes(userRoles, portalUser);
lazyEcontractInboxItem = new LazyEContractInboxItemModel(userRoles, userSmCodes);
}
We can access Spring Beans like that:
public EContractProcessService geteContractProcessService() {
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
return (EContractProcessService) FacesContext.getCurrentInstance().getApplication()
.getELResolver().getValue(elContext, null, "eContractProcessService");
}

Getting a NullPointerException through p:ajax listener

I have app.xhtml and there is a data table and panels. I'm using Apache Tomcat server. I deployed the project and there was no problem with this datatable select listener. But the project has been deployed for a week and I got a NullPointerException in datatable row select listener afterwards. When I restarted the Tomcat, the problem was solved itself. This problem occurs on every 7, 8 days period and restarting Tomcat solves this problem.
Data table is lazy and there is Person and Applications classes. Every person has many applications.
Below, some part of app.xhtml
<p:dataTable id="appDataTable"
var="applications"
value="#{appView.applicationLazy}"
rowKey="#{applications.id}"
paginator="true" rows="20"
emptyMessage="#{"No Record"}"
currentPageReportTemplate=" #{"Page"} ({currentPage}/{totalPages})"
paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink}
{RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100"
lazy="true"
selection="#{appView.selectedApplication}" selectionMode="single">
<p:ajax event="rowSelect"
onstart="ustPanel.collapse();"
update="detailPanel"
listener="#{appView.datatableRowSelectListener()}"/>
<p:ajax event="rowUnselect" update="detailPanel"/>
<f:facet name="header">
#{"Applications"}
</f:facet>
<p:column headerText="#{"name"}"
sortBy="#{appView.person.name}"
filterBy="#{appView.person.name}" >
<h:outputText value="#{appView.person.name}" >
</h:outputText>
</p:column>
<p:column headerText="#{"surname"}"
sortBy="#{appView.person.surname}"
filterBy="#{appView.person.surname}" >
<h:outputText value="#{appView.person.surname}" />
</p:column>
<p:column headerText="#{"mobilePhone"}"
sortBy="#{appView.person.mobilePhone}"
filterBy="#{appView.person.mobilePhone}"
>
<h:outputText value="#{appView.person.mobilePhone}" />
</p:column>
<p:column headerText="#{"date"}"
sortBy="#{appView.date}"
filterBy="#{appView.date}" >
<h:outputText value="#{appView.showDate(applications.date)}" />
</p:column>
<f:facet name="footer">
#{"total records"}: #{appView.applicationLazy.rowCount}
</f:facet>
</p:dataTable>
Also here some part of AppView bean class;
#ManagedBean
#ViewScoped
public class AppView extends BaseView implements Serializable {
private Applications selectedApplication;
private String name;
private String surname;
private String mobile;
private String date;
#PostConstruct
public void init() {
applicationLazy = new LazyDataModel<Basvurular>() {
#Override
public List<Applications> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
applicationLazy.setRowCount(commonService.applicationsProjection(filters));
return commonService.applicationsLazyLoad(first, pageSize, sortField, sortOrder, filters);
}
};
}
public void datatableRowSelectListener() {
try {
Locale loc = new Locale("tr", "TR");
date = selectedApplication.getDate();
name = selectedApplication.getPerson().getName().toUpperCase(loc);
surname = selectedApplication.getPerson().getSurname().toUpperCase(loc);
mobile = selectedApplication.getPerson().getMobilePhone();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Here the exception on Tomcat:
java.lang.NullPointerException
javax.el.ELException: /app.xhtml #55,173 listener="#{appView.datatableRowSelectListener()}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at
org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:53)
at
org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:102)
at
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UIData.broadcast(UIData.java:893)
at
javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute
(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute
(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at

edit p:datatable whth String ArrayList

i have this problem: if build a p:datatable from ArrayList it's impossible editing and sometimes rowSelectd not fire.
my xhtml code:
<h:form id="form">
<p:messages id="messageWiz" showDetail="true" closable="true" autoUpdate="true"/>
<h:panelGroup>
<p:commandButton id="addPattern" icon="ui-icon-add"
actionListener="#{testController.add}" process="#this"
update="patternsId" />
<p:commandButton id="deletePattern" icon="ui-icon-delete"
actionListener="#{testController.remove}"
process="#this" update="#this, patternsId"
disabled="#{empty testController.patternsSelected}" />
</h:panelGroup>
<p:dataTable id="patternsId" var="pattern" scrollable="true" scrollHeight="200"
value="#{testController.patterns}" editable="true"
editMode="cell" widgetVar="patterns" rowIndexVar="idx"
selection="#{testController.patternsSelected}"
rowKey="#{pattern}"
emptyMessage="#{label['msg.emptytable']}" styleClass="nofooter">
<p:ajax event="rowSelect" update=":form:deletePattern" />
<p:ajax event="rowUnselect" update=":form:deletePattern" />
<p:ajax event="rowSelectCheckbox" update=":form:deletePattern"/>
<p:ajax event="toggleSelect" update=":form:deletePattern" />
<p:ajax event="rowUnselectCheckbox" update=":form:deletePattern" />
<p:ajax event="cellEdit" update=":form:messageWiz" />
<p:column selectionMode="multiple" width="20" />
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{pattern}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{pattern}"
required="true" style="width:96%" autocomplete="off" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
controller code:
#ManagedBean
#ViewScoped
public class TestController implements Serializable {
private static final long serialVersionUID = 1L;
private ArrayList<String> patterns = new ArrayList<String>();
private ArrayList<String> patternsSelected;
public ArrayList<String> getPatterns() {
return patterns;
}
public void setPatterns(ArrayList<String> patterns) {
this.patterns = patterns;
}
public ArrayList<String> getPatternsSelected() {
return patternsSelected;
}
public void setPatternsSelected(ArrayList<String> patternsSelected) {
this.patternsSelected = patternsSelected;
}
public void add() {
patterns.add(new String());
}
public void remove() {
}
}
add row and edit, then close edit end inputed vaues disappear, rowSelected not fire.
You cannot achieve this with an arraylist of strings.
You must implement a list of Pattern objects (with at least id and value members)
Backing bean (testController) must implement SelectableDataModel (unique ids will help to be sure to identify and remove the right items).

Primefaces - datatable column filter textbox not appearing

I'm using PF 4.0 and I have a datatable that is lazily loaded and i'm trying to add a filter textbox to the "name" column, but the textbox is not appearing. What am I missing?
...
<p:dataTable var="user" value="#{userGroupBacking.users}" editable="true" id="userTable" paginator="true" rows="20"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" lazy="true"
filteredValue="#{userGroupBacking.filteredUsers}" >
<p:ajax event="rowEdit" listener="#{userGroupBacking.onEdit}" />
<p:column headerText="User" filterBy="#{user.name}" filterMatchMode="contains">
<h:outputText value="#{user.name}" />
</p:column>
...
backing bean:
#ManagedBean(name="userGroupBacking")
#ViewScoped
public class UserGroupBacking {
#ManagedProperty(value="#{accessBacking}")
private AccessBacking accessBacking;
public void setAccessBacking(AccessBacking accessBacking) {
this.accessBacking = accessBacking;
}
#PostConstruct
public void init() {
this.ds = databaseBacking.getDs();
if(isLoggedIn()) {
loadData();
}
}
/**
* Checks that the user is logged in
* #return
*/
public boolean isLoggedIn() {
return accessBacking.isHasAccess();
}
public LazyDataModel<User> getUsers() {
return users;
}
public List<Group> getGroups() {
return groups;
}
public List<Group> getSelectedGroups() {
return selectedGroups;
}
public List<SelectItem> getGroupsAsSelectItems() {
return groupsAsSelectItems;
}
public List<SelectItem> getUsersAsSelectItems() {
return usersAsSelectItems;
}
public String getNewGroup() {
return newGroup;
}
public void setNewGroup(String newGroup) {
this.newGroup = newGroup;
}
public List<User> getFilteredUsers() {
return filteredUsers;
}
public void setFilteredUsers(List<User> filteredUsers) {
this.filteredUsers = filteredUsers;
}
}
I figured it out. It seems that in PF 4.0, you need the filterBy code to change from:
<p:column headerText="User" filterBy="#{user.name}" filterMatchMode="contains">
<h:outputText value="#{user.name}" />
</p:column>
to:
<p:column headerText="User" filterBy="name" filterMatchMode="contains">
<h:outputText value="#{user.name}" />
</p:column>
I am just curious, is this the actual code you have in your page. Cause it should wrapped up inside <p:cellEditor> as shown in primefaces showcase
http://www.primefaces.org/showcase-labs/ui/datatableRowEditing.jsf
some thing like
<p:column headerText="Model" style="width:30%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.model}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.model}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>

Resources