【问题标题】:Icefaces ace:dataTable lazy loadingIcefaces ace:dataTable 延迟加载
【发布时间】:2012-03-09 17:39:22
【问题描述】:

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

谢谢!

【问题讨论】:

    标签: datatable loading lazy-evaluation icefaces ace-editor


    【解决方案1】:

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

    不再需要为此扩展 AbstractList

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

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

    检查:ICEFaces docs Ver. 3 ace:dataTable

    【讨论】:

    • 感谢@Nir M 的帮助,我已经完成了展示示例,但我无法运行该示例,如果可能,请您提供一个简单的示例。谢谢。
    【解决方案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;
        }
    
      }
    

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

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

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

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

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

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

          你会在

          中找到showcase.war

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

          【讨论】:

            猜你喜欢
            • 2012-04-19
            • 1970-01-01
            • 1970-01-01
            • 2015-12-13
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-03-06
            • 2021-07-13
            相关资源
            最近更新 更多