开发者

GWT RPC and data translating to GXT Grid

I am trying to translate data from server to client (GXT Grid). On the server side I have a List with data and its ok. Then I implement RPC methods and suppose that its ok too. Here is code:

  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 implemen开发者_如何学JAVAts GWTService {
    
        //private Map<String, WebasystProductData> productData;
        public List<WebasystProductData> getWebasystProductData() {
    
        WebasystConnection waConn = new WebasystConnection();
        List<WebasystProductData> waPD = waConn.getWebasystProductData();
    
        return waPD;
    }
    

Then I implement proxy using my beanmodel, beanmodelreader, listloader, listore and 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);

When start my app - no data inside grid. Dont know whats the problem, no errors... Suppose the problem is in client code


The Grid doesn't do an initial laod by its self. Did you call com.extjs.gxt.ui.client.data.Loader#load ?


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);

then just:

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

Remember that your Pojo need to implements the BeanModelTag interface

and the

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

XXX need to be the same as your Pojo properties

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜