0

I have a handler classes, I need to inject it in the custom widgets.

I tried the bind() method in ClientModule class, but it is not getting injected.

What am I supposed to do, do get the class injected.

public class ExtendedTextBoxBase extends TextBox {

    public ExtendedTextBoxBase() {

        super.addBlurHandler(textBoxBlurHandler);

    }

    @Inject
    TextBoxBlurHandler textBoxBlurHandler; /* custom handler */

}

custom handler:

public class TextBoxBlurHandler implements BlurHandler {

    @Inject
    public TextBoxBlurHandler() {
    }

    @Override
    public void onBlur(BlurEvent event) {

    }
}

Thanks, Bennet.

Bennet
  • 387
  • 1
  • 6
  • 13

2 Answers2

0

Initial reaction: did you include and @Inject statement in the method (likely constructor) where you would like to inject the handler?

If yes: could you be more specific with some code snippets?

ruggi
  • 84
  • 4
  • you mean, adding Inject annotation in the handlers construstor? Yes did... and tried adding Inject private HandlerClass handlerclass; this doesn't work. I tried bind(HandlerClass.class).to(HandlerClass.class); this will not work because its referring to same type. If possible, please show me how to inject a simple class using gin in other class. Not in View or Presenter. – Bennet Dec 25 '13 at 02:20
0

I see two potential errors:

1. You have code in constructor:

 super.addBlurHandler(textBoxBlurHandler);

so you should inject handler by constructor not by field. Gin first crate object than inject fields into class, so your handler textBoxBlurHandler is null.

2. You crate your ExtendedTextBoxBase by uibinder. If yes, you should add annotation uiField provided=true, and inject this field:

@Inject

@UiField(provided=true)

ExtendedTextBoxBase extendedTextBoxBase;
anicos
  • 21
  • 2