Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:06:43+00:00 2026-05-23T06:06:43+00:00

I have a problem. I am calling to server side on GWT. The results

  • 0

I have a problem. I am calling to server side on GWT. The results of
call is an ArrayList (result). Inside onSuccess method another
ArrayList is wrapped with the result. However, if I want to use
ArrayList lista outside of onSuccess method it contains 0 elements,
but inside is like result ArrayList. How can I solve it? I have tried
to use lista as class attribute, static attribute,… but it doesn’t
run.

Well, I have changed my code, but it doesn’t run. I call another method when onSuccess is called…

public void addContainers() throws Exception {
    gwtService.obtainAttributesDevice(1, new AsyncCallback<ArrayList<String>>(){
        @Override
        public void onFailure(Throwable caught) {
            System.out.println("ERROR");
            Window.alert(caught.getMessage());
        }
        @Override
        public  void onSuccess(ArrayList<String> result) {
            lista.addAll(0, result);
            addProjectContainers();
        }       
    });

private void addProjectContainers() throws Exception {
    RootPanel.get("mainContainer").add(new Label("Array lista 2: "+lista.toString()));
    RootPanel.get().add(new Label(String.valueOf("Array lista 2: "+lista.size())));
    for(int i = 0; i < lista.size(); i++){
        RootPanel.get().add(new Label("BOTON "+i));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:06:43+00:00Added an answer on May 23, 2026 at 6:06 am

    If it helps think of the content of onSuccess and onFailure to be threads that run separately from the rest of the code (it’s not really a thread as such, but it’s not run in synchronously with the rest of the code, thats why it’s called “asynchronous”).

    It may be help to keep things simpler and avoid massive indenting and also reduces the amount of finals you need to define, if you create a final or member variable referencing this in the class doing an asynchCall that the callback can call a method on to handle the response.

    A pseudo code sample (very simplified):

    class foo{
       protected callingClass = this;
    
       void fetchData(){
           service.getData(new Callbac(){
               onSuccess(List<Data> data){
                  callingClass.processData(data);
               }
           }
       }
       void procesData(List<Data> fetchedData){
           // Add data etc..
       }
    }
    

    EDIT About lots of code after the call:

    If you need to do lots of “stuff” after the callback, just put it in the onSuccess or the method that you make onSuccess call (such as in my sample).

    If you need to make several callbacks in sequence (where reordering them would cause errors) you should first concider making a service method that does combines those several actions (if possible), or you should do another server call inside the onSuccess callback. To simplify this, avoiding very deeply nested code, you could use a custom callback interface to define an anonymous class to use in the first callback that calls the next server call.

    I often use this interface to define something to be done after a callback using this interface (or variations of this):

    public abstract class AfterCompleteAction {
        /**
         * The stuff to do when the method receiving this callback is finished.
         */
        public abstract void run();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when calling a method from an external web service. The
I have the following problem: I have a multithreaded server-side application, where every request
Hi I have problem with calling store procedure on Oracle 10g server. This is
i have a problem calling multiple instance of a class that i have coded
I have a problem in calling a template class I have. I declared a
I have got a problem with calling a global function, which takes a pointer
I have a problem. I am coding using VS2008. I am calling webservices from
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
I have a problem with calling .Net web services with a Firefox client. A
I am calling the SQL Server Reporting Services Webservice from inside an asp.net application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.