like you already said, it is indeed a problem that the callback
request isn't finished in the time the value is returned. i'll figure
this out now.

thanks for your patience!

On Feb 5, 5:38 pm, "[email protected]"
<[email protected]> wrote:
> I'll try, hoping to be helpful! A lot of code decision depends on
> exactly what you want to do with this code. I do some assumption now:
> 1- you need to load at some kind of startup your variable 'result '
> 2- you need to read the content of the 'result' variable later in the code.
>
> I would do something as follows for what concerns MediaStation class:
>
> public class MediaStation{
>     private static String result = "nothing";
>     public static String getXMLContent(String path){
>         return MediaStation.result;
>     }
>     public static void loadResultVariable() {
>         RequestBuilder requestBuilder = new
> RequestBuilder(RequestBuilder.GET, path);
>             try {
>                 requestBuilder.sendRequest(null, new RequestCallback() {
>                     public void onError(Request request, Throwable
> exception) {
>                         MediaStation.requestFailed(exception);
>                     }
>                     public void onResponseReceived(Request request,
> Response response) {
>                         MediaStation.result = response.getText();
>                     }
>                 });
>             } catch (RequestException ex) {
>                 MediaStation.requestFailed(ex);
>             }
>     }}
>
> (I have not tried to compile this code, please consider there may be errors)
>
> Then from outside this class I would call loadResultVariable() at the
> beginning, that is when your code is initializing. Then you can use
> easily getXMLContent, but after having ensured that the server request
> has already finished.
> Note that there are many other issues that can arise due to callbacks,
> issues that can be addressed in many ways, but I suppose you can get a
> lot of info about them.
>
> BR,
> Federica
>
> reinika ha scritto:
>
> > yes, that might be an issue.
> > i know it goes back to the basics of programming, but maybe you can
> > give me an outline how i can achieve to call a method for reading a
> > xml file and returning its content (as you say you've never seen
> > something like that before).
>
> > thanks!
>
> > On Feb 5, 5:00 pm, "[email protected]"
> > <[email protected]> wrote:
>
> >> I try to suggest you something, but I hope not to give a trivial
> >> suggestion to you...
>
> >> Are you sure that you call MediaStation.getXMLContent() after the
> >> callback returns? For what I can read in your code, you send the
> >> callback in the try / catch block, then the next statement that is
> >> executed is "return MediaStation.result". So you may not have finished
> >> the callback execution at that point. Anyway this is a way of using a
> >> getter function in conjunction with a request that I have never seen 
> >> before.
>
> >> BR,
> >> Federica
>
> >> reinika ha scritto:
>
> >>> hi!
>
> >>> maybe somebody could help me with this. i'm trying to set the
> >>> "MediaStation" static variable "result" in an inner class,
> >>> unfortunately the the method "getXMLContent(...)" still returns the
> >>> initially set string "nothing" when calling it with:
> >>> ---
> >>> Window.alert("Content: " + MediaStation.getXMLContent(XML_FILEPATH));
> >>> ---
> >>> I also checked, that the inner method "onResponseReceived" is called
> >>> and "response.getText();" also returns a result (see the commended
> >>> alert window statement).
>
> >>> source follows:
> >>> ---
> >>> ...
>
> >>> public class MediaStation{
> >>>    private static String result = "0";
>
> >>>        ...
>
> >>>    public static String getXMLContent(String path){
> >>>            RequestBuilder requestBuilder = new RequestBuilder
> >>> (RequestBuilder.GET, path);
> >>>            MediaStation.result = "nothing";
>
> >>>            try {
>
> >>>                    requestBuilder.sendRequest(null, new RequestCallback() 
> >>> {
> >>>                            public void onError(Request request, Throwable 
> >>> exception) {
> >>>                                    MediaStation.requestFailed(exception);
> >>>                            }
> >>>                            public void onResponseReceived(Request 
> >>> request, Response response)
> >>> {
> >>>                                    MediaStation.result = 
> >>> response.getText();
> >>>                                    //Window.alert("XML file successfully 
> >>> read: " +
> >>> MediaStation.result);
> >>>                            }
> >>>                    });
> >>>            } catch (RequestException ex) {
> >>>                    MediaStation.requestFailed(ex);
> >>>            }
> >>>            return MediaStation.result;
> >>>    }
> >>> ...
> >>> }
> >>> ---
>
> >>> thanks for your help! bye!
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to