I am using PrimeFaces 5.1 in my JSF application. On the listing page of this application I am using Primefaces Datatable with pagination. Values for one of the column in the table is a primefaces commandLink that on click is defined to call action method defined in a JSF ManagedBean class that has SessionScope. This datatable itself is defined in an XHTML page that uses template XHTML that has h:form defined. Thus this datatable is nested in that h:form.
The problem I am facing is that the method defined in ManagedBean is only getting invoked from commandLinks rendered on the first page of the datatable, whereas from commandLinks on subsequent pages action method is not getting invoked. What I also noticed is that as the total records are less than 100 so when I set the value for 'rows' attribute of the datatable in XHTML to 100 rows per page, only a single page gets rendered and then when I select 10 or 50 rows per page option from the pagination drop down list in the listing page multiple pages show up but the link works fine. However, from the code, if I set the rows value to 50 or 10 rows per page in the XHTML code the issue seems to happen.
I checked firebug JS as well as Chrome JS console and there are no errors nor does the tomcat log file shows any log error even though I have set the javax.faces.PROJECT_STAGE context-param in web.xml to Development. What could be the reason for this behavior and how can I resolve this?
Below is my JSF snippet for the datatable:
<p:dataTable id="data" widgetVar="dataTable" var="customer" value="#{customerServicePortaltBacking.customers}"
paginator="true"
rows="50"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="10,50,100">
<p:column style="width: 14%">
<f:facet name="header">
<p:outputLabel value="#{msg['customerId']}" styleClass="covFont"/>
</f:facet>
<h:outputText value="#{customer.customerId}" styleClass="covFont"/>
</p:column>
<p:column style="width: 66%">
<f:facet name="header">
<p:outputLabel value="#{msg['name']}" styleClass="covFont"/>
</f:facet>
<h:outputText value="#{customer.name}" styleClass="covFont"/>
</p:column>
<p:column style="width: 10%">
<f:facet name="header">
<p:outputLabel value="#{msg['deptId']}" styleClass="covFont"/>
</f:facet>
<h:outputText value="#{customer.deptId}" styleClass="covFont"/>
</p:column>
<p:column style="width: 10%">
<f:facet name="header">
<p:outputLabel value="#{msg['view']}" styleClass="covFont"/>
</f:facet>
<p:commandLink id="invoiceButton" value="#{msg['customers.invoices']}" action="#{customerServicePortaltBacking.goInvoiceCategories(customer)}"
></p:commandLink>
</p:column>
</p:dataTable>
Below is the code from Managed Bean class:
package com.assetworks.csportal;
import com.assetworks.csportal.orm.*;
import org.apache.commons.lang.StringUtils;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.text.MessageFormat;
import java.util.*;
import java.util.logging.Logger;
@ManagedBean
@SessionScoped
public class CustomerServicePortaltBacking {
private static final Logger LOGGER =
Logger.getLogger(CustomerServicePortaltBacking.class.getName());
private List<Customer> customers = null;
private Stack<Screens> screensStack = new Stack<>();
//Screen
private Screens screen = Screens.CustomerBrowse;
private String customerName;
private Customer customer;
public String getCustomerName() {
if(customerName == null){
String name = new DataAccess().getCustomerName(getContactId());
if(name == null)
name = "";
customerName = name;
}
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public List<Customer> getCustomers() {
if(customers == null){
customers = new DataAccess().getCustomers(getContactId());
}
List<Customer> filteredCustomers = new LinkedList<>();
if(hasValue(this.getSearch())) {
String search = getSearch().toUpperCase();
for (Customer customer : customers) {
if(customer.getCustomerId().indexOf(search) != -1 || customer.getName().toUpperCase().indexOf(search) != -1 || customer.getDeptId().indexOf(search) != -1){
filteredCustomers.add(customer);
}
}
}
else{
filteredCustomers = customers;
}
return filteredCustomers;
}
public String goCusomerList(){
screensStack.clear();
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:data");
if(dataTable != null) {
dataTable.resetValue();
dataTable.processUpdates(FacesContext.getCurrentInstance());
}
setScreen(Screens.CustomerBrowse);
return Screens.CustomerBrowse.getId();
}
public String goHome(){
search = null;
return goCusomerList();
}
public String goInvoiceCategories(Customer customer){
categories = null;
this.customer = customer;
this.setScreen(Screens.CustomerServiceCategory);
return Screens.CustomerServiceCategory.getId();
}
public String goBack() {
this.screen = screensStack.pop();
return getScreen().getId();
}
public boolean hasValue(String str){
return str != null && str.length() > 0;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String authenticateUser() {
isUserAuthenticated = true;
return goCusomerList();
}
public void setScreen(Screens screen) {
screensStack.push(getScreen());
this.screen = screen;
}
public Screens getScreen() {
return this.screen;
}
public String getMessage(String key, Object[] args){
String result = "[Key " + key + " not found in messages.properties]";
try {
FacesContext context = FacesContext.getCurrentInstance();
ResourceBundle bundle =
ResourceBundle.getBundle("messages",
context.getViewRoot().getLocale());
result = new MessageFormat(bundle.getString(key)).format(args);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public String getVersion(){
return Application.VERSION;
}
public String getScreenlabel() {
return getMessage(screen.getId(), new Object[0]);
}
public Customer getCustomer() {
return customer;
}
public void setCustomers(List<Customer> customers) {
this.customers = customers;
}
public boolean isCustomerExternal(){
return customer.getDeptId().toUpperCase().startsWith("UFL");
}
}