2011-06-28 81 views
0

我正在嘗試將數據從服務器轉換爲客戶端(GXT Grid)。 在服務器端,我有一個數據列表和它的好。 然後我實現RPC方法並假設它也可以。這裏是代碼:GWT RPC和數據轉換爲GXT Grid

  1. GWTService

    @RemoteServiceRelativePath("gwtservice") 
    public interface GWTService extends RemoteService { 
        public List<WebasystProductData> getWebasystProductData(); 
    } 
    
  2. GWTServiceAsynch

    public interface GWTServiceAsync { 
        public void getWebasystProductData(AsyncCallback<List<WebasystProductData>> callback); 
    } 
    
  3. GWTServiceImpl

    public class GWTServiceImpl extends RemoteServiceServlet implements GWTService { 
    
        //private Map<String, WebasystProductData> productData; 
        public List<WebasystProductData> getWebasystProductData() { 
    
        WebasystConnection waConn = new WebasystConnection(); 
        List<WebasystProductData> waPD = waConn.getWebasystProductData(); 
    
        return waPD; 
    } 
    

然後我使用我的beanmodel,beanmodelreader,listloader,listore和grid實現代理。

... 

rpc = RpcInit.initRpc(); 

RpcProxy<BeanModel> proxy = new RpcProxy<BeanModel>() { 

    @Override 
    public void load(Object loadConfig, AsyncCallback callback) { 
     rpc.getWebasystProductData(callback); 
    } 
}; 

BeanModelReader reader = new BeanModelReader(); 
BaseListLoader loader = new BaseListLoader(proxy, reader); 
ListStore<BeanModel> store = new ListStore<BeanModel>(loader); 

List<ColumnConfig> col = new ArrayList<ColumnConfig>(); 
ColumnConfig column = new ColumnConfig(); 
column.setId("productIdWA"); 
column.setHeader("ProductID"); 
column.setWidth(50); 
col.add(column); 

column = new ColumnConfig(); 
column.setId("productNameWA"); 
column.setHeader("productName"); 
column.setWidth(120); 
col.add(column); 

column = new ColumnConfig(); 
column.setId("productPriceWA"); 
column.setHeader("productPrice"); 
column.setWidth(80); 
col.add(column); 

column = new ColumnConfig(); 
column.setId("categoryIdWA"); 
column.setHeader("categoryID"); 
column.setWidth(80); 
column.setAlignment(HorizontalAlignment.RIGHT); 
col.add(column); 

時候開始我的應用程序 - 內網的數據。不知道最新的問題,沒有錯誤... 假設問題出在客戶端代碼

+0

你是蘇WebasystProductData是一個Serializable類?什麼是waConn.getWebasystProductData()返回的List的實現; ? – jonasr

回答

0

網格並沒有做自己的初始設計。你有沒有調用com.extjs.gxt.ui.client.data.Loader#load?

+0

是的,我做了 - loader.load();在實施電網之前 – BraginiNI

0
RpcProxy<List<WebasystProductData>> proxy= new RpcProxy<List<WebasystProductData>>() { 
     @Override 
     protected void load(Object loadConfig,AsyncCallback<List<WebasystProductData>> callback) { 

      getWebasystProductData(config,callback); 
     } 
    }; 
    BeanModelReader reader = new BeanModelReader(); 
    ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader); 
    ListStore<BeanModel> store = new LisStore<BeanModel>(loader); 

然後只是:

Grid<BeanModel> grid = new Grid<BeanModel>(store,column); 
    grid.addListener(Events.Attach, new Listener<GridEvent<BeanModel>>() { 
     public void handleEvent(GridEvent<BeanModel> be) { 
      loader.load(); 
     } 
     }); 

記住,你的POJO的需要實現BeanModelTag接口

column = new ColumnConfig(); 
column.setId("XXX"); 

XXX必須與您的POJO屬性