openfaces datatable problem

1.2k Views Asked by At

i have tried to build a very simple page that includes openfaces datatable component.

i have tried to enable pagination for it. i have done the instruction just like its

developer's guide, but when i get these two variables in my back bean, the pageStart is

always is zero!

this is my .xhtml file

   <?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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:o="http://openfaces.org/"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
    <h:head>
        <title>My Facelets Page</title>
        <meta http-equiv="keywords" content="enter,your,keywords,here" />
        <meta http-equiv="description"
            content="A short description of this page." />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

        <link rel="stylesheet" type="text/css" href="styles.css" />
    </h:head>
    <h:body>
        <div id="Demo" class="content-inner-wrapper">
                        <f:view>
                            <h:form id="form">
                            <o:dataTable id="citiesTable"
                 value="#{testBean.lazyModel}"
                 var="city"
                 customDataProviding="true"
                 pageSize="15"
                 totalRowCount="#{testBean.count}"
                 rowDataByKey="#{testBean.rowByKey}"
                 rowKey="#{city.id}"
                 styleClass="cities">
      <o:singleRowSelection/>
      <o:columnReordering/>
      <f:facet name="columnMenu">
        <o:columnMenu/>
      </f:facet>

      <o:column id="name" header="City" sortingExpression="#{city.cityTitle}"
                bodyStyle="padding-left: 10px;">
        <f:facet name="subHeader">
          <o:inputTextFilter expression="name"/>
        </f:facet>
        <h:outputText value="#{city.cityTitle}"/>
      </o:column>

      <o:column id="population" header="Population" sortingExpression="#{city.cityCode}"
                style="width: 20%;"
                bodyStyle="text-align: right; padding-right: 15px;">
        <f:facet name="subHeader">
          <o:comboBoxFilter expression="population" options="#{CitiesList.ranges}"/>
        </f:facet>
        <h:outputText value="#{city.cityCode}">
          <f:convertNumber type="number"/>
        </h:outputText>
      </o:column>

<f:facet name="below">
        <h:panelGroup>
          <o:dataTablePaginator id="paginator"
                                style="margin-left: 240px; margin-top: 10px;"
                                />

          <h:outputText value="Event log:"
                        style="margin-top: 10px; margin-bottom: 5px; border-bottom: 1px solid black;"/>
        </h:panelGroup>
      </f:facet>

    </o:dataTable>
                            </h:form>
                            </f:view>
                </div>
    </h:body>
</html>

and this is my back bean:

package backbeans;

import java.util.List;

import javax.ejb.EJB;

import order.TblBaseCities;
import order.TblBaseCitiesFacadeLocal;

import org.openfaces.util.Faces;

public class TestBean {

    @EJB
    TblBaseCitiesFacadeLocal cities;

    public List<TblBaseCities> getLazyModel(){
        int pageStart = Faces.var("pageStart", Integer.class);
        return cities.findAll(pageStart,Faces.var("pageSize",Integer.class));
    }

    public int getCount(){
        return cities.findAll().size();
    }

    public TblBaseCities getRowByKey() {
        Integer key = Faces.var("rowKey", Integer.class);
        return cities.findById(key);
    }
}

i am using openfaces 3.0, myfaces 2.0.4 and weblogic 10.3.3 server

thanks in advance

1

There are 1 best solutions below

2
On

It seems that you have forgot to place the DataTablePaginator component itself. You should place it in "above" and/or "below" facet. Just make sure that paginator's id is specified explicitly for it to function properly.

<o:dataTable ...>
  <f:facet name="above">
    <o:dataTablePaginator id="paginator"/>
  </f:facet>
  ...
</o:dataTable>