Injecting Handlers in Custom Widget

194 Views Asked by At

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.

2

There are 2 best solutions below

1
ruggi On

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?

0
anicos On

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;