2011-11-24 61 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()); 
}