openfaces数据表问题

时间:2011-04-30 11:41:41

标签: datatable openfaces

我试图构建一个包含openfaces数据表组件的非常简单的页面。

我试图为它启用分页。我已完成指令,就像它的

一样

开发人员指南,但是当我在我的后台bean中获得这两个变量时,pageStart是

总是零!

这是我的.xhtml文件

   <?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>

这是我的背豆:

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

我正在使用openfaces 3.0,myfaces 2.0.4和weblogic 10.3.3服务器

提前致谢

1 个答案:

答案 0 :(得分:2)

您似乎忘记了自己放置DataTablePaginator组件。您应该将它放在“上方”和/或“下方”方面。只需确保明确指定paginator的id才能使其正常运行。

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