PDA

View Full Version : RPCProxy and gwt-dispatch



baczek00
27 Aug 2014, 8:51 AM
Hi!I'm trying to do a little something in GXT and I want to use List from
GXT and RPCProxy.
Let's say I have a bean class of Foo. I have an action called
ListFooAction and result associated with it - ListFooResult.
ListFooAction is empty, since I want to list all my Foo's, and
ListFooResult contains a list of all Foo objects - List<Foo>.
Now what I'd like to do, is to load my foo objects using gwt-dispatch
inside RPCProxy load method. After looking into GXT list examples, I
assume my RPCProxy should be like this: RPCProxy<List<Foo>>. I have to
provide implementation for abstract method - load:



@Override
protected void load(Object loadConfig, AsyncCallback<List<Foo>> callback) {

}
};


Now I'd like to execute my ListFooAction using DispatchAsync inside that
method to load all my Foo objects. Doing so, I would have an
AsyncCallback<ListFooResult>. But RPCProxy load method has
AsyncCallback<List<Foo>>, and I have List<Foo> inside my FooResult. How
can I "transfer" list from my result to the callback from the load
method? Is this possible? Or maybe there is better approach to achieve
what I'm trying to do?

twoSeven
9 Jul 2015, 11:39 AM
did you fix it?

baczek00
13 Jul 2015, 3:40 PM
did you fix it?
Yes. Here is a sample of my code:



public PagingLoader<PagingLoadConfig, PagingLoadResult<BaseModelData>> getLoaderOfflineModelData(final Boolean commitTrasactionAfterOK, final DBAction action, final NaviSoftFormOperation formParent, final String sSQL, final String nameGrid) {
RpcProxy<PagingLoadConfig, PagingLoadResult<BaseModelData>> proxy = new RpcProxy<PagingLoadConfig, PagingLoadResult<BaseModelData>>() {
@Override
public void load(final PagingLoadConfig loadConfig, final AsyncCallback<PagingLoadResult<BaseModelData>> callback) {
AsyncCallback<PrimaryKeyResult> callbackPK = new AsyncCallback<PrimaryKeyResult>() {
@Override
public void onFailure(Throwable caught) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void onSuccess(PrimaryKeyResult result) {
primaryKey = result.getListPrimaryKey();
dispatch.getDispatchAsync().execute(new LoaderData(commitTrasactionAfterOK, action, sSQL, formParent.getClass().getName(), nameGrid, loadConfig), new AsyncCallback<LoaderDataResult>() {

@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}

@Override
public void onSuccess(LoaderDataResult result) {
callback.onSuccess(result.getPagingLoader());
}
});
}
};
}
};
loaderPaging = new PagingLoader<PagingLoadConfig, PagingLoadResult<BaseModelData>>(proxy);
return loaderPaging;
}