pagination with lazy loading in primefaces donesn't work properly - jsf

I am getting a problem with lazy loading in dataTable but couldn't to know where the problem is,
here is my xhtml page code:
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Application</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Element per page"/>
<p:selectOneMenu value="#{applicationManagementListBean.pageSize}">
<f:selectItem itemLabel="5" itemValue="5"/>
<f:selectItem itemLabel="10" itemValue="10"/>
<f:selectItem itemLabel="30" itemValue="30"/>
<f:selectItem itemLabel="50" itemValue="50"/>
<p:ajax event="change" update="applicationDataList"/>
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton value="New application"
action="inscription.xhtml?faces-redirect=true" ajax="false" />
<p:dataTable id="applicationDataList" value="#{applicationManagementListBean.applications}"
var="app" paginator="true"
rows="#{applicationManagementListBean.pageSize}" lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<p:column headerText="Code">
<h:outputText value="#{app.code}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{app.name}" />
</p:column>
<p:column headerText="Abreviate name">
<h:outputText value="#{app.abrevName}" />
</p:column>
<p:column headerText="Status">
<h:outputText value="#{app.status.description}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</f:view>
and the bean code:
#ManagedBean
#ViewScoped
public class ApplicationManagementListBean implements Serializable {
private static final long serialVersionUID = 1L;
#ManagedProperty(value = "#{applicationManagementService}")
public ApplicationManagementRemote applicationManagementService;
private Integer pageSize = 3;
private DataProxyLazyDataModel data;
public void setApplicationManagementService(
ApplicationManagementRemote applicationManagementService) {
this.applicationManagementService = applicationManagementService;
}
public LazyDataModel<Object> getApplications() {
data = new DataProxyLazyDataModel(applicationManagementService);
data.setPageSize(pageSize);
return data;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public DataProxyLazyDataModel getData() {
return data;
}
public void setData(DataProxyLazyDataModel data) {
this.data = data;
}
}
when I click on the next page button nothing happen
please help
thanks a lot
best regards, Rachid
primegaces 3.4.2, liferay portal 6.1, eclipse

try adding setRowCount() to your lazyDataModel.
for example:
lazyDataModel.setRowCount(rows);
where rows represents total records in your Database to display in DataTable.
In your case code is:
data.setRowCount(rows);

Related

Datatable filter is not working after update of datatable bean

DataTable list filter is working properly in normal time but if i click active/inactive/all button then datatable filter is not working. After writing counter 1 in search field the table is just showing active counter 1. But when i click inactive/all button is not refreshing showing inactive list.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>
<ui:define name="body">
<h:form id="form">
<p:growl id="growl"/>
<p:commandButton value="New" action="#{sdcController.newCounter}"/>
<h:selectOneRadio value="#{sdcListController.rdoChk}" onchange="submit()"
valueChangeListener="#{sdcListController.activeInactiveStateChanged}">
<f:selectItem itemValue="1" itemLabel="Active" />
<f:selectItem itemValue="0" itemLabel="Inactive" />
<f:selectItem itemValue="-1" itemLabel="All" />
</h:selectOneRadio>
<p:dataTable id="sdcList" var="sdc" value="#{sdcListController.sdcBeanList}"
rows="15" paginator="true"
rowIndexVar="row"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginatorPosition="bottom"
widgetVar="counterListTable"
>
<f:facet name="header">
<p:outputPanel style="margin-left: 80%; height: 7px;">
<h:outputText value="Search:" />
<p:inputText id="globalFilter" onkeyup="PF('counterListTable').filter()" />
</p:outputPanel>
SDC/Counter Management
</f:facet>
<p:column headerText="Counter Status" width="15%" filterBy="#{sdc.counterStatus}" filterStyle="display:none; visibility:hidden;">
<h:outputText value="#{sdc.counterStatus}" style="vertical-align: middle;padding-top: 4px"/>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
Above code is .xhtml file
#ManagedBean
#RequestScoped
public class SdcListController {
private List<SdcBean> sdcBeanList;
private int rdoChk;
#ManagedProperty(value = "#{sdcServiceLayer}")
private SdcServiceLayer sdcServiceLayer;
private int sessionScId;
#ManagedProperty(value = "#{param.counterId}")
private int counterId;
#ManagedProperty(value = "#{param.scId}")
private int scId;
#PostConstruct
public void init() {
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
sessionScId = QpaUtilities.strToIntDefaultZero(sessionMap.get("sessionScId").toString());
rdoChk = QpaUtilities.strToIntDefaultM999(QpaUtilities.nullToEmptyString(sessionMap.get("sdcRdoChk")));
rdoChk = (rdoChk == -999) ? 1 : rdoChk;
initPageList(rdoChk);
}
private void initPageList(int state) {
sdcBeanList = sdcServiceLayer.getAllSDCListForSearch(sessionScId, state);
//rdoChk = "1";
}
public void activeInactiveStateChanged(ValueChangeEvent e) {
rdoChk = QpaUtilities.strToIntDefaultZero(e.getNewValue().toString());
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("sdcRdoChk", rdoChk);
initPageList(rdoChk);
}
public List<SdcBean> getSdcBeanList() {
return sdcBeanList;
}
public void setSdcBeanList(List<SdcBean> sdcBeanList) {
this.sdcBeanList = sdcBeanList;
}
public void setRdoChk(int rdoChk) {
this.rdoChk = rdoChk;
}
public int getRdoChk() {
return rdoChk;
}
}
Above code is sdcListController.java file

I'm trying to initilize an attribut in a bean with #viewScoped but it does not work

hello everyone I'm trying to build a webpage with two oneMenu the second one depending on the second one. My XHTML file is below as well as my bean.
when I try to create a new "structureAttache" I have the following problem
TemplateStructureAttache.xhtml #40,139 value="#{structureBean.structureAttache.intituleStructure}": Target Unreachable, 'structureAttache' returned null
and when I use the method initStruc to create a new structureAttache then I call it in the listener of my first ajax, I succeed to create a structureAttache but when I do it for the second time, it seems like the value already exit in the DB and it refuses please help me to solve this issue
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dresen.dresen.Beans;
import com.dresen.dresen.ServiceInterface.IArrondissementService;
import com.dresen.dresen.ServiceInterface.IStructureService;
import com.dresen.dresen.entities.Arrondissement;
import com.dresen.dresen.entities.StructureAttache;
import com.dresen.dresen.entities.CategorieStructure;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import com.dresen.dresen.ServiceInterface.ICategorieStructureService;
import com.dresen.dresen.ServiceInterface.IDepartementService;
import com.dresen.dresen.entities.Departement;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
/**
*
* #author Vivien Saa
*/
#ManagedBean
#ViewScoped
public class StructureBean implements Serializable{
#ManagedProperty(value = "#{IStructureService}")
private IStructureService iStructureService;
#ManagedProperty(value = "#{IArrondissementService}")
private IArrondissementService iArrondissementService;
#ManagedProperty(value = "#{ICategorieStructureService}")
private ICategorieStructureService iCategorieStructureService;
#ManagedProperty(value ="#{IDepartementService}")
private IDepartementService iDepartementService;
private long idDepartement;
private long idArrondissement;
private long idCategorieStructure;
private StructureAttache structureAttache;
private List<Arrondissement> listArrondissement;
private List<Departement> listDepartement;
private List<CategorieStructure> listCategorieStructure;
private Arrondissement arrondissement = new Arrondissement();
private CategorieStructure CategorieStructure = new CategorieStructure();
public StructureBean() {
structureAttache = new StructureAttache();
idDepartement = 0L;
idArrondissement = 0L;
idCategorieStructure = 0L;
}
public ICategorieStructureService getiCategorieStructureService() {
return iCategorieStructureService;
}
public void setiCategorieStructureService(ICategorieStructureService iCategorieStructureService) {
this.iCategorieStructureService = iCategorieStructureService;
}
public long getIdDepartement() {
return idDepartement;
}
public void setIdDepartement(long idDepartement) {
this.idDepartement = idDepartement;
}
public IDepartementService getiDepartementService() {
return iDepartementService;
}
public void setiDepartementService(IDepartementService iDepartementService) {
this.iDepartementService = iDepartementService;
}
public List<Departement> getListDepartement() {
return iDepartementService.findAllDepartement();
}
public void setListDepartement(List<Departement> listDepartement) {
this.listDepartement = listDepartement;
}
public long getIdCategorieStructure() {
return idCategorieStructure;
}
public void setIdCategorieStructure(long idCategorieStructure) {
this.idCategorieStructure = idCategorieStructure;
}
public List<CategorieStructure> getListCategorieStructure() {
return iCategorieStructureService.findAllCategorieStructure();
}
public void setListCategorieStructure(List<CategorieStructure> listCategorieStructure) {
this.listCategorieStructure = listCategorieStructure;
}
public IStructureService getiStructureService() {
return iStructureService;
}
public void setiStructureService(IStructureService iStructureService) {
this.iStructureService = iStructureService;
}
public IArrondissementService getiArrondissementService() {
return iArrondissementService;
}
public void setiArrondissementService(IArrondissementService iArrondissementService) {
this.iArrondissementService = iArrondissementService;
}
public long getIdArrondissement() {
return idArrondissement;
}
public void setIdArrondissement(long idArrondissement) {
this.idArrondissement = idArrondissement;
}
public StructureAttache getStructureAttache() {
return structureAttache;
}
public void setStructureAttache(StructureAttache structureAttache) {
this.structureAttache = structureAttache;
}
public List<Arrondissement> getListArrondissement() {
return iArrondissementService.findArrondissementByIdDepart(idDepartement);
}
public void setListArrondissement(List<Arrondissement> listArrondissement) {
this.listArrondissement = listArrondissement;
}
public Arrondissement getArrondissement() {
return arrondissement;
}
public void setArrondissement(Arrondissement arrondissement) {
this.arrondissement = arrondissement;
}
public CategorieStructure getCategorieStructure() {
return CategorieStructure;
}
public void setCategorieStructure(CategorieStructure CategorieStructure) {
this.CategorieStructure = CategorieStructure;
}
public void initStruc() {
structureAttache = new StructureAttache();
}
public StructureAttache createStructure(){
System.out.println("vvsssssssssvsssssssssssssssssssssssvv why don't you work");
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.createStructureAttache(structureAttache);
}
public StructureAttache findStructureById(){
return iStructureService.findStructureAttacheById(structureAttache.getId());
}
public StructureAttache updateStructure(){
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.updateStructureAttache(structureAttache);
}
public List<StructureAttache> findAllStructure(){
return iStructureService.findAllStructureAttache();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Application de gestion du personnel des services déconcentrés du MINESEC EXTREME NORD</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:body>
<div id="menu">
<ui:include src="Menu.xhtml"/>
</div>
<f:view>
<p:dialog widgetVar="dlg" header=" Enregistrer une nouvel nouvelle Structure d'attache " hideEffect="explode" showEffect="explode" modal="true">
<h:form id="formAjouter" >
<p:panelGrid id="panelAjouter" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<p:commandButton value="Enregistrer" action="#{structureBean.createStructure()}" oncomplete="PF('dlg').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="dl" header=" Modifier une structure d'attache" hideEffect="fold" showEffect="explode" resizable="true">
<h:form id="formModifier" enctype="multipart/form-data">
<p:panelGrid id="panelGModifier" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<h:inputHidden id="number" value="#{structureBean.structureAttache.id}" />
<p:commandButton value="Modifier" action="#{structureBean.updateStructure()}" oncomplete="PF('dl').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
</f:view>
<f:view>
<h:form id='tableForm'>
<p:dataTable value="#{structureBean.findAllStructure()}" var="item" paginator="true" rows="10" paginatorTemplate=" {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} " id="table" rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{structureBean.structureAttache}" rowKey="#{item.id}">
<f:facet name="header">
La liste des Structures d'attache
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Structure"/>
</f:facet>
<h:outputText value="#{item.intituleStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Code/Abréviation Structure"/>
</f:facet>
<h:outputText value="#{item.codeStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Arrondissement"/>
</f:facet>
<h:outputText value="#{item.arrondissement.intituleArrondissement}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Département"/>
</f:facet>
<h:outputText value="#{item.arrondissement.departement.intituleDepartement}"/>
</p:column>
</p:dataTable>
<p:toolbar>
<f:facet name="left">
<p:commandButton type="push" onclick="PF('dlg').show();" value="Nouvelle Structure" icon="ui-icon-disk">
<p:ajax update=":formAjouter:panelAjouter" resetValues="true" />
</p:commandButton>
<p:commandButton onclick="PF('dl').show()" value="Modifier Structure" update=":formModifier:panelGModifier" icon="ui-icon-arrowrefresh-1-w"/>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton type="push" title="Save" image="ui-icon-disk" />
<p:commandButton type="push" title="Update" icon="ui-icon-arrowrefresh-1-w"/>
<p:commandButton type="push" title="Print" image="ui-icon-print"/>
</f:facet>
</p:toolbar>
</h:form>
</f:view>
</h:body>
</html>
You can use a method to initialize your attributes as you would like to, then through an AJAX or and actionListener, you call the method that will do the job before you try to use the attribute.

#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");
}

p:dataTable filtering doesn't work with template

I'm trying to create a filtering datatable with PrimeFaces framework.
My issue is that the datatable is displayed but filtering option doesn't work , help please !!
My page.xhtml looks like :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition>
<h5>
<h:form>
<p:dataTable var="student" value="#{studentWizard.students}" widgetVar="studentTable" emptyMessage="Aucun élève trouvé" id="tableStudent" filteredValue="#{studentWizard.filteredStudents}" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Chercher tous les champs:" />
<p:inputText id="globalFilter" onkeyup="studentTable.filter()" style="width:150px" placeholder="Entrer le mot-clé"/>
</p:outputPanel>
</f:facet>
<p:column filterBy="#{student.studentCode}" headerText="Code de l'élève" filterMatchMode="contains">
<h:outputText value="#{student.studentCode}"/>
</p:column>
<p:column filterBy="#{student.firstName}" headerText="Prénom" filterMatchMode="contains">
<h:outputText value="#{student.firstName}"/>
</p:column>
<p:column filterBy="#{student.lastName}" headerText="Nom" filterMatchMode="contains">
<h:outputText value="#{student.lastName}"/>
</p:column>
<p:column headerText="Modifier" >
<p:commandButton value="Modifier" type="submit" ajax="false" icon="ui-icon-update"/>
</p:column>
</p:dataTable>
</h:form>
</h5>
</ui:composition>
</html>
and My Java Bean :
#ManagedBean(name="studentWizard")
#Component
#ViewScoped
public class StudentWizard implements Serializable {
public StudentWizard() {}
private static final long serialVersionUID = 1L;
private Student student;
private List<Student> students;
private List<Student> filteredStudents;
#PostConstruct
public void init() {
students = getAllStudent();
}
public List<Student> getFilteredStudents() {
return filteredStudents;
}
public void setFilteredStudents(List<Student> filteredStudents) {
this.filteredStudents = filteredStudents;
}
#Autowired
private StudentManager studentManager;
public void setStudentManager(StudentManager studentManager) {
this.studentManager = studentManager;
}
public Student getstudent() {
return student;
}
public StudentManager getStudentManager() {
return studentManager;
}
public void setstudent(Student student) {
this.student = student;
}
public void save() {
studentManager.saveStudent(student);
student = new Student();
}
public List<Student> getAllStudent() {
return studentManager.getAllStudent();
}
public Student getStudentById(int id) {
return studentManager.getStudentById(id);
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
}
This is my home web page
<h:body>
<p:layout style="min-width:400px;min-height:100px;">
<p:layoutUnit position="center" size="400" >
</p:layoutUnit>
</p:layout>
<p:layout style="min-width:400px;min-height:500px;">
<p:layoutUnit position="west" size="244" >
<h5>
<h:form>
<p:menu toggleable="true">
<p:submenu label="Eleves">
<p:menuitem value="Nouvel élève" action="#{menuView.setSelectedItem(1)}" update=":globalPanel" />
<p:menuitem value="Consultation" action="#{menuView.setSelectedItem(2)}" update=":globalPanel" />
</p:submenu>
<p:submenu label="Personnels">
</p:submenu>
<p:submenu label="Notes">
</p:submenu>
<p:submenu label="Caisses">
</p:submenu>
<p:submenu label="Salaires">
</p:submenu>
<p:submenu label="Référentiel">
</p:submenu>
</p:menu>
</h:form>
</h5>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:panelGroup id ="globalPanel" >
<h:panelGroup id="inscriptionPanel" rendered="#{menuView.selectedItem == 1}" header="Inscription" style="margin-bottom:20px">
<ui:include src="/inscription.xhtml" />
</h:panelGroup>
<h:panelGroup id="testerPanel" rendered="#{menuView.selectedItem == 2}" header="Consultation" style="margin-bottom:20px" >
<ui:include src="/consul.xhtml" />
</h:panelGroup>
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>

How to display text in a dialog box?

The Data that I have entered in the input text field of the prime faces data table is not displayed in the dialog box JSF file and Data is not displayed in the dialog box
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add/Remove Row</title>
</h:head>
<body>
<h:form id="form">
<p:dataTable id="buss" value="#{busBean.mediumBusModel}" var="bus"
selection="#{busBean.selectedBus}" selectionMode="single" >
<p:column headerText="Brand" style="width:5%">
<p:inputText value="#{bus.brand}" />
</p:column>
<p:column headerText="Model" style="width:5%">
<p:inputText value="#{bus.model}" />
</p:column>
<p:column headerText="Action" style="width:10%">
<p:commandButton actionListener="#{busBean.addBus()}" icon="ui-icon-plus" update=":form" ajax="false" title="add"/>
<p:commandButton actionListener="#{busBean.removeBus(bus)}" icon="ui-icon-minus" update=":form" ajax="false" title="remove"/>
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:displayBus" oncomplete="PF('singleBusDialog').show()"/>
</f:facet>
</p:dataTable>
<br/>
<p:dialog id="dialog" header="Bus Detail" widgetVar="singleBusDialog" resizable="false"
showEffect="fade" hideEffect="explode">
<h:panelGrid id="displayBus" columns="2" cellpadding="4">
<h:outputText value="Brand:" />
<h:outputText value="#{bus}" style="font-weight:bold"/>
<h:outputText value="Model:" />
<h:outputText value="#{bus}" style="font-weight:bold"/>
</h:panelGrid>
</p:dialog>
</h:form>
</body>
</html>
Below is the bean class that I have used
package com.bus.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import com.bus.bean.Bus;
#ManagedBean
#SessionScoped
public class BusBean implements Serializable {
private List<Bus> busList;
private Bus selectedBus;
private BusDataModel mediumBusModel;
public BusBean() {
busList=new ArrayList<Bus>();
busList.add(new Bus("a","b"));
mediumBusModel = new BusDataModel(busList);
//populateRandomCars(cars, 50);
}
public List<Bus> getBusList()
{
return busList;
}
public void setBusList(List<Bus> busList) {
this.busList = busList;
}
public void addBus()
{
Bus newBus=new Bus();
busList.add(newBus);
}
public Bus getSelectedBus() {
return selectedBus;
}
public void setSelectedBus(Bus selectedBus) {
this.selectedBus = selectedBus;
}
public void removeBus(Bus bus)
{
busList.remove(bus);
}
public BusDataModel getMediumBusModel() {
return mediumBusModel;
}
}
-------------------------------------------------------
package com.bus.bean;
import java.util.List;
import javax.faces.model.ListDataModel;
import com.bus.bean.Bus;
import org.primefaces.model.SelectableDataModel;
public class BusDataModel extends ListDataModel<Bus> implements SelectableDataModel<Bus> {
public BusDataModel() {
}
public BusDataModel(List<Bus> data) {
super(data);
}
#Override
public Bus getRowData(String rowKey) {
//In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
List<Bus> buss = (List<Bus>) getWrappedData();
for(Bus bus : buss) {
if(bus.getModel().equals(rowKey))
return bus;
}
return null;
}
#Override
public Object getRowKey(Bus bus) {
return bus.getBrand();
}
}
-----------------------------------------------------------------------------------------------/
package com.bus.bean;
import java.io.Serializable;
public class Bus implements Serializable
{
public String model;
public String brand;
public Bus()
{
}
public Bus(String Model,String Brand)
{
this.model = model;
this.brand = brand;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getBrand() {
System.out.println("in set:"+brand);
return brand;
}
public void setBrand(String brand) {
System.out.println("in set:"+brand);
this.brand = brand;
}
#Override
public boolean equals(Object obj) {
if(obj == null)
return false;
if(!(obj instanceof Bus))
return false;
Bus compare = (Bus) obj;
return compare.model.equals(this.model);
}
#Override
public int hashCode() {
int hash = 1;
return hash * 31 + model.hashCode();
}
#Override
public String toString() {
return "Bus{" + "model=" + model + ", brand=" + brand + '}';
}
enter code here
}
Please let me know how to get the data that I have entered in the text field of Primefaces data table to the dialog box
You should use the selected value from the datatable.
selection="#{busBean.selectedBus}"
So , in your dialog box
<h:outputText value="Brand:" />
<h:outputText value="#{busBean.selectedBus.brand}" />
Also,
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:displayBus,:form:dialog" oncomplete="PF('singleBusDialog').show()"/>
Updating the dialog box with value of the selected row.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add/Remove Row</title>
</h:head>
<body>
<h:form id="form">
<p:growl id="messages" showDetail="true"/>
<p:contextMenu for="buss">
<p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="PF('busTable').showCellEditor();return false; "/>
</p:contextMenu>
<p:dataTable id="buss" var="bus" value="#{busBean.busModel}" editable="true" editMode="cell" widgetVar="busTable"
selection="#{busBean.selectedBus}">
<p:ajax event="cellEdit" listener="#{busBean.onCellEdit}" update=":form:messages" />
<p:column selectionMode="single" style="width:2%" />
<p:column headerText="Brand" style="width:25%">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{bus.brand}" /></f:facet>
<f:facet name="input"><p:inputText id="brandInput" value="#{bus.brand}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Model" style="width:25%">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{bus.model}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{bus.model}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Action" style="width:10%">
<p:commandButton actionListener="#{busBean.addBus()}" icon="ui-icon-plus" update=":form" ajax="false" title="add"/>
<p:commandButton actionListener="#{busBean.removeBus(bus)}" icon="ui-icon-minus" update=":form" ajax="false" title="remove"/>
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:buss,:form:displayBus,:form:dialog" oncomplete="PF('singleBusDialog').show()"/>
</f:facet>
</p:dataTable>
<br/>
<p:dialog id="dialog" header="Bus Detail" widgetVar="singleBusDialog" resizable="false"
showEffect="fade" hideEffect="explode">
<h:panelGrid id="displayBus" columns="2" cellpadding="4">
<h:outputText value="Brand:" />
<h:outputText value="#{busBean.selectedBus.brand}" style="font-weight:bold"/>
<h:outputText value="Model:" />
<h:outputText value="#{busBean.selectedBus.model}"/>

Resources