Results 1 to 2 of 2
Thread: Callbacks
- 08-18-2009, 02:16 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 3
- Rep Power
- 0
Callbacks
Hi All,
I'm currently writing client-side code for a web-app in Java (using GWT, which converts it into JS), but I think my question is more a Java question than a GWT one.
The code currently looks, roughly, like this:
But of course, myVariable remains uninitialized, and myMethod() returns only "xyz". If I'm looking to change my global variable, myVariable, how would I go about doing that?Java Code:public class MyProgram { [INDENT]String myVariable; MyServiceAsync service = GWT.create(MyService.class); ... [INDENT]public String myMethod() { [INDENT]service.getSomething(new AsyncCallback<String>() { [INDENT]public void onFailure(Throwable caught) { [INDENT]myVariable = "fail";[/INDENT] } public void onFailure(Throwable caught) { [INDENT]myVariable = "success";[/INDENT] }[/INDENT] }[/INDENT]return myVariable + "xyz"; }[/INDENT]}[/INDENT] }
- 08-18-2009, 11:03 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Well apart from the fact that it could never compile because there are two identical onFailure(..) methods in the AsyncCallback class, in principle the code should work, although given that the AsyncCallback methods are called asynchronously, the 'myVariable' String will be updated to 'success' or 'failure' at some indeterminate time after myMethod returns. That's what asynchronous means.
If you want help with runtime problems in code you post, it helps to post code that will compile...
Similar Threads
-
How to implement Destruction callbacks in Spring Framework
By Java Tip in forum Java TipReplies: 0Last Post: 03-31-2008, 10:18 AM -
How to use Initialization callbacks in Spring Framework
By Java Tip in forum Java TipReplies: 0Last Post: 03-31-2008, 10:16 AM -
How to implement Destruction callbacks in Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:50 PM -
How to use Initialization callbacks in Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks