Gxt Rpc Grid调用客户端并用作本地网格

时间:2011-11-24 06:40:55

标签: grid gxt

我的服务器中有ArrayList我希望在客户端的网格中显示它。我正在使用RPC机制来实现此目的。 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
             * 
             *
             * 
             * 
             */ 

1 个答案:

答案 0 :(得分: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());
}