PDA

View Full Version : GWT-RPC How to invoke onFailure method from server side explicitly?



ashly.jos@gmail.com
14 Apr 2011, 7:51 AM
Hi,

On an Async call (GWT-TPC), how can I invoke onFailure method from serverside explicitly?

I need to handle few exception scenarios at the client side with respect to exceptions in the server side.

please help...

thanks in advance,
-ash

cimballi
14 Apr 2011, 8:46 AM
Only have your code throw an exception and the onFailure method will be called.

ashly.jos@gmail.com
14 Apr 2011, 12:10 PM
thanks cimballi, I got that.

But, how do I throw different type of exceptions? I need to show different messages for different type of exceptions.

I have tried throwing different exceptions with different messages as:

throw new StatusCodeException(1, "Error adding values");

But when onFailure method is invoked, it receives Throwable object with description "There was some error on invoking service" (can't remember the exact description as I'm not in front of the program now).

Is there any way to differentiate the errors at the client side?

thanks,
-ash

cimballi
14 Apr 2011, 12:17 PM
That's because you did not specify these exceptions in the methods signature of the GWT service class. You can search for "gwt handling exceptions" in a search engine.

blay
15 Apr 2011, 6:52 AM
Yep, just define your custom exception (it should extend IsSerializable class) and in the signature of the method in your service you have to declare that exception can be thrown.

In the "onFailure" method you simply compare like:

if (throwable instanceOf CustomException){
...
}