2011-11-24 76 views
0

我在我的服务器中有一个ArrayList我想在客户端的网格中显示它。我正在使用RPC机制来达到这个目的。 RPC调用成功了,但在添加分页时却不起作用。如果没有以正确的方式做到这一点,请指导我正确地做到这一点。Gxt Rpc网格调用客户端并用作本地网格

我只是把ArrayList添加到客户端,然后添加到网格。我认为这是造成问题的原因。

这里是我的代码:

ArrayList valls=new ArrayList(); 
    public ContentPanel mainPanel1 = new ContentPanel(); 
    public PagingToolBar toolBar = new PagingToolBar(10); 
    public ContentPanel cpc=new ContentPanel(); 

    public ContentPanel mainPanel = new ContentPanel(); 
    public ContentPanel cp = new ContentPanel(); 
    public ListStore<BeanModelType> clientList=new ListStore<BeanModelType>(); 

    public ListStore<BeanModelType> createGrid() 
    { 

    System.out.print("METHOD DDDDDDDDD"); 
    final FeedServiceAsync feedService =Registry.get(RSSReaderConstants.FEED_SERVICE); 

    feedService.createNewFeed(new AsyncCallback<Feed>() { 

     @Override 
     public void onFailure(Throwable caught) 
     { 
      // TODO Auto-generated method stub 
      Info.display("RSSReader", "Unable to create a new feed"); 
      System.out.print("ERRORRRRRR"); 
     } 
     @Override 
     public void onSuccess(Feed result) 
     { 
      ArrayList valls=result.getVal();  
      PagingModelMemoryProxy proxy = new PagingModelMemoryProxy(TestData.getClients(result.getVal())); 
      PagingLoader loader = new BasePagingLoader(proxy); 
      loader.setRemoteSort(true); 

       /*  

       final PagingToolBar toolBar = new PagingToolBar(5); 
       toolBar.bind(loader); 
       loader.load(0, 5); 

       */ 
       clientList.add(TestData.getClients(valls)); 

       /* 
       * if we remove the above code only shows the pagination not the content value 
       * 
       * Actual code shoiuld be like this 
       * 
       * 
       *clientList= new ListStore<BeanModelType>(loader); 
       * 
       * returns clientList; 
       * 
       * 
       * but int his method its not working sirrrr aM SORRY TO SAY THIS 
       * 
       * 
       */ 

       clientList = new ListStore<BeanModelType>(loader); 
       toolBar.bind(loader); 
       loader.load(0, 10); 
       loader.setRemoteSort(true); 

     } 
    }); 

return clientList; 

} 
/* 
============================================================================== 
code for grid 
=====================================================================================*/ 
/* 
     * 
     * Grid Starts 
     * 
     */ 
       List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); 

        ColumnConfig column = new ColumnConfig();  
        column.setId("name");  
        column.setHeader("CLIENT");  
        column.setWidth(200);  
        configs.add(column); 
        column = new ColumnConfig("name1", "CAMPAIGN", 150); 
        column.setAlignment(HorizontalAlignment.LEFT); 
        configs.add(column); 

        column = new ColumnConfig("name2", "SITE", 100); 
        column.setAlignment(HorizontalAlignment.LEFT); 
        configs.add(column); 

        column = new ColumnConfig("name3", "ADUNIT", 100); 
        column.setAlignment(HorizontalAlignment.LEFT); 
        configs.add(column); 

        column = new ColumnConfig("name4", "START", 100); 
        column.setAlignment(HorizontalAlignment.LEFT); 
        configs.add(column); 



        ColumnModel cm = new ColumnModel(configs); 
        Grid<BeanModelType> grid = new Grid<BeanModelType>(createGrid(), cm); 
        grid.setStyleAttribute("borderTop", "none"); 
        grid.setAutoExpandColumn("name"); 
        grid.setAutoExpandColumn("name1"); 
        grid.setAutoExpandColumn("name2"); 
        grid.setAutoExpandColumn("name3"); 
        grid.setAutoExpandColumn("name4"); 
        grid.setBorders(true); 
        grid.setStripeRows(true); 
        //grid.getView().setAutoFill(true); 
        //grid.setAutoWidth(true); 

        cp.setBodyBorder(false); 
        cp.setHeading("Employee List");  
        cp.setButtonAlign(HorizontalAlignment.CENTER); 
        cp.setSize(1440,609); 
        cp.setFrame(true); 
        cp.setAnimCollapse(false); 
        cp.setLayout(new FillLayout(Orientation.VERTICAL)); 
        cp.setBottomComponent(toolBar); 
        cp.add(grid); 
        cp.setSize("", "370"); 

        mainPanel.add(cp); 


      /* 
      * 
      * End Of Grid 
      * 
      * 
      * 
      * 
      */ 

回答

2

你不能做到这一点。 feedService.createNewFeed是异步进程。你在createGrid方法返回的是一个空的clientList。重新配置内部网格onSuccess方法

public void onSuccess(Feed result){ 
.... 
clientList = new ListStore<BeanModelType>(loader); 
toolBar.bind(loader); 
loader.setRemoteSort(true); 
grid.reconfigure(clientList, grid.getColumnModel()); 
}