我正在尝试将数据从服务器转换为客户端(GXT网格)。 在服务器端,我有一个包含数据的列表,确定无误。 然后我实现RPC方法并假设它也可以。这是代码:
GWTService
@RemoteServiceRelativePath("gwtservice")
public interface GWTService extends RemoteService {
public List<WebasystProductData> getWebasystProductData();
}
GWTServiceAsynch
public interface GWTServiceAsync {
public void getWebasystProductData(AsyncCallback<List<WebasystProductData>> callback);
}
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 :(得分:0)
网格本身不会执行初始加载。你有没有打电话给com.extjs.gxt.ui.client.data.Loader#load?
答案 1 :(得分: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属性相同