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

  • Home
  • SEARCH
  • 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 6390223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:30:02+00:00 2026-05-25T03:30:02+00:00

Working with the Google Web Toolkit i have written an application which is based

  • 0

Working with the Google Web Toolkit i have written an application which is based on the Model-View-Controller concept. Now my ClientController class has two objects of the types ClientModel and ClientView which are declared private and non-static. With an object for asynchronous calls i have written some Remote Procedure Calls which do work, however attaching an anonymous object from the type AsyncCallback<T> makes me a problem, as i can not access the two ClientModel and ClientView objects without writing some nasty final variables in my function like you can see below:

package com.foo.bar;

/**
 * Represents the main handler holding delegates and controlling the contents of
 * the {@link ClientModel} and pushes notifications and message to both the
 * {@link ClientModel} and the {@link ClientView}.
 */
public class ClientController {
    /**
     * Exposes asynchronous functions to call the server component via RPC.
     */
    public static final MyServiceAsync mySvc = GWT.create(myService.class);

    /**
     * Represents the model associated with the {@link ClientController} object.
     */
    private ClientModel theModel = null;
    /**
     * Represents the view associated with the {@link ClientController} object.
     */
    private ClientView theView = null;

    /**
     * Creates a new {@link ClientController} object and instantiates both the
     * {@link ClientModel} and the {@link ClientView}.
     */
    public ClientController() {
        this.theModel = new ClientModel();
        this.theView = new ClientView(this.theModel);
    }

    /* some more code */

    /**
     * Tries to login the specified user and updates the {@link ClientView}
     * object to either an error message or the main interface.
     * 
     * @param user
     *            {@link User} object representing the user to login
     */
    public void loginUser(final User user) {
        ///////////////////////////////////////////////
        // THIS IS UGLY AND I DON'T KNOW HOW TO FIX THIS
        ///////////////////////////////////////////////
        final ClientModel currentModel = this.theModel;

        // Execute the login protocol
        ClientController.mySvc.login(user, new AsyncCallback<Boolean>() {
            /**
             * The request was successfully executed. Returns a boolean value
             * indicating whether the user was logged in.
             * 
             * @param result
             *            true, if the user was logged in; otherwise, false.
             */
            @Override
            public void onSuccess(Boolean result) {
                // The user was successfully logged in and we must both store
                // him in the model and then update the view.
                if (result) {
                    // TODO: Update the view to show the chat itself and save
                    // the current User to the ClientModel.
                    System.out.println("The User " + user.getUsername()
                            + " is now logged in!");
                    // Anonymous object can not access the theModel and theView
                    // objects of ClientController directly ...
                    // drunk, fix later!
                    // UGLY FIX FOR NOW
                    currentModel.setCurrentUser(user);
                } else {
                    // TODO: Unhide the error label of the login form and output
                    // some nice error message.
                    System.out.println("Login failed for User "
                            + user.getUsername() + "!");
                }
            }

            /**
             * The request provoked an error.
             */
            @Override
            public void onFailure(Throwable up) {
                try {
                    throw up; // Ha ha
                } catch (Throwable e) {
                    // Who cares?
                }
            }
        });
    }
}

For now I am using a final pointer to the internal model in loginUser which is hoghlighted two times. Can anyone explain me whether there is a better solution without moving theModel and theView to static members? It is annoying to write such “final wrappers” in every function you access either of the components…

  • 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-25T03:30:02+00:00Added an answer on May 25, 2026 at 3:30 am

    When you create an instance of a non-static inner class, or an instance of an anonymous class, that instance has an implicit binding to the instance of the outer class that created it. You can access members of the outer class from within the inner class using OuterClassName.this.member.

    In your case: ClientController.this.theModel

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working a on a Google Web Toolkit project. I want to show a word
Trying to avoid re-inventing the wheel here. I have a Google Web Toolkit page
We are looking at integrating a full-blown GWT (Google Web Toolkit 2.0) application with
I have an ASP.net web service that I'm using for a web application which
I have a Google Map that suddenly stopped working for no apparent reason (I
Hopefully this is a quickie: I've been doing a lot of Java/Google Web Toolkit
I have a client that wants to use Google Chrome for an internal web
I am building a web application that uses a lot of Javascript. Now I
I'm currently working on a Google Maps project and am implementing a search function.
I am working with both amq.js (ActiveMQ) and Google Maps . I load my

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.