3

I am using Hibernate 4, Spring 3 and JSF 2.0 with Weblogic 10.3.6 as server.

I have two datatables in one page, in order to populate datatable I am using lazy loading.

The problem I am facing is when both the datatables are displayed, then pagination doesn't work. It does goes to page 2 and 3 and so forth, but records in datatable remains the same for both datatable. If I remove either one of them then pagination works perfectly.

I have noticed that even filter is not working when I have multiple datatables. Both datatables are in a single form, they both do have two different ManagedBeans and both are of view scope. I have tried with request scope, but didn't solve my problem.

How can I resolve this issue?

JSF Code

<h:form id="form">
    <!-- Master form -->
        <p:dataTable id="dataTable" var="req" lazy="true" value="#{emp.lazyModel}"
            paginator="true" rows="10" 
                         selection="#{emp.selectedRequest}"
                        selectionMode="single">                             
      <p:ajax event="rowSelect" listener="#{emp.onRowSelect}" />            
            <p:column id="empNo" filterBy="#{req.empNo}"   
                headerText="Request No" footerText="contains"  
                filterMatchMode="endsWith">                 
                <h:outputText value="#{req.empNo}" />
            </p:column>         
            other columns
                    </p:dataTable>              
        <!-- Detail form -->
        <p:dataTable id="dataTableDet" var="reqAct" lazy="true" value="#{dept.lazyModel}"
            paginator="true" rows="1"
            rowsPerPageTemplate="5,10">
            <f:facet name="header">                  
            Emp Details  
        </f:facet>
       <p:column>
                <f:facet name="header">
                    <h:outputText value="SLNo" />
                </f:facet>
                <h:outputText value="#{reqAct.slNo}" />
            </p:column>        
            <p:column id="empNo" filterBy="#{reqAct.empNo}"   
                headerText="Request No" footerText="contains"  
                filterMatchMode="endsWith">                 
                <h:outputText value="#{reqAct.empNo}" />
            </p:column>
        other columns
        </p:dataTable>      
        </h:form> 

Managedbean First Datatable

@Named("emp")
@Scope("view")
@PostConstruct
    public LazyDataModel<Employee> getLazyModel() {
        if (lazyModel == null) {
            lazyModel = new LazyRequestDataModel(empList, empService) {

            };          
        }

        return lazyModel;
    }

Managedbean Second Datatable

@Named("dept")
@Scope("view")
@PostConstruct
    public LazyDataModel<Department> getLazyModel() {
        if (lazyModel == null) {
            lazyModel = new LazyRequestActivitiesDataModel(deptList,
                    deptService) {

            };
        }

        return lazyModel;
    }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jacob
  • 14,463
  • 65
  • 207
  • 320

1 Answers1

2

Not sure it will help , but anyway it a better approach

Change your @PostConstruct into public void , like this (do it for both Beans)

@PostConstruct
public void init(){
    initTable();
}

private void initTable(){
    lazyModel = new LazyRequestActivitiesDataModel(deptList,deptService);
}

public LazyDataModel<Department> getLazyModel() {
    return lazyModel;

}

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • By adding the following in web.xml did help ` com.sun.faces.enableRestoreView11Compatibility true ` Thanks – Jacob Dec 26 '12 at 09:13
  • OK , weird... http://stackoverflow.com/questions/1715985/com-sun-faces-enablerestoreview11compatibility-what-use-instead-in-jsf-1-2 cause **com.sun.faces.enableRestoreView11Compatibility is a JSF 1.2 setting that tells JSF 1.2 to behave like JSF 1.1.** – Daniel Dec 26 '12 at 09:23
  • I was getting some error messages in Firebug console and when I searched google to resolve firebug error, I found this. By adding this in web.xml solved my pagination problem as well. However I have encountered another problem [here](http://stackoverflow.com/questions/14040049/primefaces-datatable-onrowselect-method-causing-nullpointer-exception) – Jacob Dec 26 '12 at 11:36
  • Daniel By adding this would cause any issues? Because I am using JSF2.0. ` com.sun.faces.enableRestoreView11Compatibility true ` – Jacob Dec 26 '12 at 11:46
  • Don't know , but it doesn't looks like a good idea... I have a feeling that its cause of your view scope , *javax.faces.application.ViewExpiredException* could be the reason – Daniel Dec 26 '12 at 12:11