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 7555139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:31:31+00:00 2026-05-30T11:31:31+00:00

We are evaluating using GIN in out GWT project and have had good results

  • 0

We are evaluating using GIN in out GWT project and have had good results with typical injection via constructor arguments. The thing we have had difficulty with is field level injection. The fields always end up being null. Does anyone have a good example of how to properly achieve filed level injection with GIN?

Update:

Here is some example code similar to ours:

public class MVP implements EntryPoint {

  public static final HandlerManager EVENT_BUS = new HandlerManager(null);
  private final MVPInjector _injector = GWT.create(MVPInjector.class);

  public void onModuleLoad() {
    // set up layout for module
    RootLayoutPanel.get().add(mainPanel);

    // initialize presenters
    ListPresenter listPresenter = _injector.listPresenter();
    DetailPresenter detailPresenter = _injector.detailPresenter();

    listPresenter.go(listContainer);
    detailPresenter.go(detailContainer);

    // simulate data coming in from RPC call
    EVENT_BUS.fireEvent(new DataReadyEvent(getData()));
  }
}

public class ListPresenter {

  private final HandlerManager _eventBus;
  private final Map<String, Fruit> _myRecords = new HashMap<String, Fruit>();
  private final Display _view;

  @Inject
  public ListPresenter(Display argView, HandlerManager argEventBus) {
    _eventBus = argEventBus;
    _view = argView;
  }

  public void go(HasWidgets argContainer) {
    argContainer.clear();
    argContainer.add(_view.asWidget());
  }

  public interface Display {
    public Widget asWidget();

    public void clear();

    public SingleSelectionModel<ViewProxy> getSelectionModel();

    public void setData(List<ViewProxy> argData);
  }
}

public class DetailPresenter {

  private final HandlerManager _eventBus;
  private final Display _view;
  private Fruit _myRecord;

  @Inject
  private ImagePresenterFactory _imagePresenterFactory;

  @Inject
  private TestPresenter _testPresenter;

  @Inject
  public DetailPresenter(Display argView, HandlerManager argEventBus) {
    _view = argView;
    _eventBus = argEventBus;
  }

  public void go(HasWidgets argContainer) {
    argContainer.clear();
    argContainer.add(_view.asWidget());

    if (_testPresenter != null) {
      _testPresenter.go();
    }
  }

  public interface Display {
    public Widget asWidget();

    public HasText getDescriptionControl();

    public HasClickHandlers getImageControl();

    public HasText getNameControl();

    public HasClickHandlers getSaveControl();

    public void setEnabledControls(boolean argEnabled);
  }
}

public class TestPresenter {

  @Inject
  HandlerManager _eventBus;

  public TestPresenter() {}

  public void go() {
    if (_eventBus != null) {
      _eventBus.toString();
    }
    else {
      // event bus was not injected
    }
  }
}

@GinModules(MVPModule.class)
public interface MVPInjector extends Ginjector {

  DetailPresenter detailPresenter();

  ListPresenter listPresenter();

}

public class MVPModule extends AbstractGinModule {

  @Provides
  @Singleton
  public HandlerManager getEventBus() {
    return MVP.EVENT_BUS;
  }

  @Provides
  public TestPresenter getTestPresenter() {
    return new TestPresenter();
  }

  @Override
  protected void configure() {
    bind(ListPresenter.Display.class).to(ListView.class);
    bind(DetailPresenter.Display.class).to(DetailView.class);
    bind(ImagePresenter.Display.class).to(ImagePopup.class);
    install(new GinFactoryModuleBuilder().build(ImagePresenterFactory.class));
  }

  public interface ImagePresenterFactory {
    public ImagePresenter createImagePresenter(ImageResource argImage);
  }

}

In the above code, I have removed most of the code that doesn’t involve GIN. The TestPresenter that the DetailPresenter requires is injected successfully but the HandlerManager that the TestPresenter requires is always null. As you can see, the injected HandlerManager is not used in the constructor.

  • 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-30T11:31:32+00:00Added an answer on May 30, 2026 at 11:31 am

    Update, looking at sample code:

    @Provides
    public TestPresenter getTestPresenter() {
      return new TestPresenter();
    }
    

    Because you are creating it yourself, it assumes you’ve dealt with any injections. Remove this method, and it will invoke the default constructor (injecting there if needed), then visit any other injection site.

    One other issue you could be running into: there are several HandlerManager impls, make sure all of your references to HandlerManager use the same package.


    Original answer:

    They will be null when the constructor is running, but this makes sense – how could they be any other value, when the injector hasn’t had a chance to assign all the fields yet. Consider how this could would run (expressed here as questionably legal java, as fields may not be public):

    InstanceToInject instance = new InstanceToInject(...);
    instance.field = provideFieldValue();
    

    By the time the field is even eligible to be assigned, your constructor has already run.

    If the field is null when another method is run, make sure that method is not being run by the constructor, but is after injection has finished its work. Other cases where it may yet be null would be @Inject annotated setters.

    Assuming it is none of those cases (easiest way to check is by setting a breakpoint, and making sure the injector isn’t in the call stack), be certain that the field does have an @Inject, and that it isn’t bound to a null instance.

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

Sidebar

Related Questions

I am evaluating using CouchDB in my new Django-project. Is there a good database
I'm evaluating and looking at using CherryPy for a project that's basically a JavaScript
I'm evaluating using Coco/R vs. ANTLR for use in a C# project as part
I am evaluating if there is a performance variation between calls made using GWT-RPC
I have begun evaluating MonoDroid. (I've built many apps using Android+Eclipse) I created new-from-template
I have just started evaluating whether or not I should be using OData influenced
Our team is evaluating using WCF Data Services (formerly ADO.NET Data Services), and have
I'm trying to compile a project using appcelerator (crossplatform dev for iphone/android). Just evaluating
PHP has the habit of evaluating (int)0 and (string)0 as empty when using the
When evaluating dojo.require statements, dojo tracks which modules and resources have been required and

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.