【问题标题】:GWT Requestfactory coarse grained wrapper objectGWT Requestfactory 粗粒度包装对象
【发布时间】:2023-03-03 21:15:01
【问题描述】:

目前在我的应用程序中,我们正在使用 GWT RequestFactory。我们有多个 EntityProxy。几个 finder 方法从服务层返回列表。由于我们在应用程序中使用分页,因此我们在列表中返回预先配置的 EntityProxy 数量。我们还需要 EntityProxy 的总数,以便在我们单独请求的分页 UI 中显示。我们想创建一些包装器对象,将 List 和 totalRecord 计数封装在单个类中。因此,在单个请求中,我们可以获得列表和记录计数。使用 requestfactory 最好做什么?注意:我是 GWT RequestFactory 的初学者。

【问题讨论】:

    标签: gwt requestfactory


    【解决方案1】:

    Umit 的回答非常正确。我只会添加一个抽象分页处理的层。当您拥有 BasicTables 和 BasicLists 以通过同一接口 PageProxy(例如,用于分页)处理所有数据时,这非常有用

    public interface PaginationInfo extends ValueProxy {
        public int getTotalRecords();
        //either have the manual page info
        public int getPageNumber();
        //or use the count API on GAE (returned by your db request as a web safe String)
        public String getCount();
    }
    
    public interface PageProxy extends ValueProxy {
        public PaginationInfo getPageInfo();
    }
    
    public interface MyEntityProxy extends EntityProxy  {}
    
    public interface MyEntityPageProxy extends PageProxy {
        public List<MyEntityProxy> getEntities();
    }
    

    【讨论】:

      【解决方案2】:

      嗯,你可以使用类似的东西:

      public interface MyEntityProxy extends EntityProxy  {}
      
      public interface MyEntityPageProxy extends ValueProxy {
          public List<MyEntityProxy> getEntities();
          public int getTotalRecords();
      }
      

      最好使用通用的PageProxy 接口(即MyEntityPageProxy&lt;T extends EntityProxy&gt;),但是由于bug,这是不可能的,或者至少只能通过一种解决方法。

      因此,对于您想要拥有分页支持的每个EntityProxy,您必须创建一个单独的PageProxy 接口。

      【讨论】: