Reputation: 20581
If RPC method return Void
, then will it call onSuccess()
method? Or I must to return some value to cause RPC to call onSuccess()
method?
Upvotes: 2
Views: 2291
Reputation: 4407
If your server side method returns an object, the code would look like:
rpcService.doSomething(ArgumentToServerSide, new AsyncCallback<ReturnType>() {
@Override
public void onSuccess(ReturnType result) {
// DO what you expect on Success
}
@Override
public void onFailure(Throwable caught) {
// DO what is expected on failure
}
In case server side method does not return anything i.e. return type is void
then your code would look like:
rpcService.doSomething(ArgumentToServerSide, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
// DO what you expect on Success
}
@Override
public void onFailure(Throwable caught) {
// DO what is expected on failure
}
Did you notice that onSuccess
method gets a object of Type Void
, which is a placeholder for keyword void (Check documentation at http://docs.oracle.com/javase/6/docs/api/java/lang/Void.html)
So essentially if your method returns a certain type, onSuccess
and onFailure
will return that type, else it will return type Void
Hope this helps.
Upvotes: 3
Reputation: 16079
If asynchronous request finishes successfully regardless its return value onSuccess()
method will be called. So, you don't have to return the object which is not necessary.
void onSuccess(T result) Called when an asynchronous call completes successfully. From documentation
Upvotes: 5