3

有没有人有一个使用 ace:dataTable 进行延迟加载的小例子?..我不明白如何实现 LazyDataModel 类的加载方法..以及如何通过此方法从数据库中获取数据..

谢谢!

4

5 回答 5

4

ace:dataTable已经在 ICEFaces 中“内置”了延迟加载机制(至少对于 3.x 及更高版本)。

不再需要为此扩展AbstractList

您需要做的就是将lazy="true"添加到您的标签中,并确保“ value ”属性指向一个扩展LazyDataModel的类......您只需要在那里实现接受起始页、页面的抽象方法大小、排序和过滤参数。

也不要忘记使用分页并确定页面的大小(“行”属性)。

检查:ICEFaces 文档版本。3 王牌:数据表

于 2012-07-11T14:05:38.433 回答
2

这是工作示例

myDataTableLazy.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:icecore="http://www.icefaces.org/icefaces/core"> 
<h:head> 
<title>DataTable</title>  
</h:head> 
<h:body> 


   <h:form>
            <ace:dataTable id="carTable"
                       value="#{myDataTableLazy.lazyModel}"
                       var="car"   
                       rows="5"                    
                       paginator="true" 
                       lazy="true" >

                <ace:column id="exp" rendered="false">
                    <ace:expansionToggler />
                </ace:column>

                <ace:column headerText="Id">
                    <ice:outputText value="#{car.id}" />
                </ace:column>
                <ace:column headerText="Name">
                    <ice:outputText value="#{car.name}" />
                </ace:column>

        </ace:dataTable>


        <h:commandButton id="invio" value="Invio"    actionListener="#{myDataTableLazy.cicla}"  > 
         </h:commandButton>  

    </h:form> 

MyDataTableLazy

  package my;

  import java.io.Serializable;
  import java.util.List;

  import javax.annotation.PostConstruct;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped; 
  import javax.faces.event.ActionEvent;

  import org.icefaces.ace.model.table.LazyDataModel;
  import org.icefaces.samples.showcase.example.ace.dataTable.DataTableLazyLoading;
  import org.icefaces.samples.showcase.metadata.context.ComponentExampleImpl;

  @ManagedBean(name="myDataTableLazy")
  @SessionScoped
  public class MyDataTableLazy   implements Serializable { 

    private LazyDataModel<Car> lazyModel;

    @PostConstruct
      public void init() {
        lazyModel = new LazyCarDataModel();
      }

    public LazyDataModel<Car> getLazyModel() {
        return lazyModel;
    }

    public void setLazyModel(LazyDataModel<Car> lazyModel) {
        this.lazyModel = lazyModel;
    } 


     public void cicla(ActionEvent e)  { 

         List<Car> lista = (List<Car>) lazyModel.getWrappedData();

         for (Car car : lista) {
           System.out.println( car.getName() );
         } 

     }


  }

LazyCarDataModel

  package my;

  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;

  import org.icefaces.ace.model.table.LazyDataModel;
  import org.icefaces.ace.model.table.SortCriteria;

  public class LazyCarDataModel extends LazyDataModel<Car> {
    List<Car> carList;

    public LazyCarDataModel(){ 
        carList = new ArrayList<Car>();
        carList.add(new Car(1, "FiatLazy"));
        carList.add(new Car(2, "FerrariLazy"));
        carList.add(new Car(3, "PorscheLazy"));
        carList.add(new Car(4, "MaseratiLazy"));
        carList.add(new Car(5, "MercedesLazy"));
        carList.add(new Car(6, "BMWLazy"));
        carList.add(new Car(7, "ToyotaLazy"));
        carList.add(new Car(8, "FordLazy"));
        carList.add(new Car(9, "Alfa RomeoLazy"));
        carList.add(new Car(10, "SuzukiLazy"));
        carList.add(new Car(11, "RenaultLazy"));

        setRowCount(carList.size());
    }

    @Override
    public List<Car> load(int first, int pageSize, SortCriteria[] arg2, Map<String, String> arg3) {
        ArrayList list = new ArrayList<Car>();

        int initial = first;

        for (int i = initial; i < initial + pageSize && i < carList.size(); i++) {
            list.add(carList.get(i));
        }

        return list;
    }

  }
于 2016-10-18T07:29:52.147 回答
0

ICEFaces ice/ace:DataTable 下面适用于原生 Java 集合。Datatable 只需在集合上调用 get(idx) 方法即可访问集合中的元素。

我建议您应该考虑在较低级别实现延迟加载/分页,例如实现您自己的java.util.AbstractList

从实现其抽象 get() 方法和调试开始,以了解 icefaces 数据表的工作原理,或者您可以查看 ice/ace:dataTable ice/ace:dataPaginator 源。

于 2012-03-14T21:04:26.867 回答
0

由于 IceFaces Ace 是 PrimeFaces 2 的副本/分支,因此 PrimeFaces 文档和示例可能会有所帮助。primefaces.org/showcase-labs/ui/datatableLazy.jsf

于 2012-03-15T22:48:27.547 回答
0

Pheraps 这有点离题,但要构建展示示例:请访问http://www.icesoft.org/java/downloads/icefaces-downloads.jsf

您可以选择 ICEfaces 4.x ICEfaces 3.x ICEfaces 1.x 选项卡

下载 ICEfaces-xx0-bin.zip 文件(您进行注册)

解压并进入你要编译的文件夹,例如在命令shell中,进入...\ICEfaces-3.3.0-bin.zip\ICEfaces-3.3.0-bin\icefaces\samples\showcase\showcase

启动命令(你必须有 maven): mvn package

你会在里面找到showcase.war

\ICEfaces-3.3.0-bin\ICEfaces-3.3.0-bin\icefaces\samples\showcase\showcase\target

于 2016-10-19T09:40:40.687 回答