I'm implementing a custom widget extending Composite
and implementing Focusable
and HasFocusHandlers
.
The widget contains two widgets in a panel that I wrap into a FocusPanel
that I use to initialize the widget. My constructor looks something like that:
public CustomBox() {
panel = new VerticalPanel();
...
panel.add(caption);
panel.add(icon);
...
focusPanel = new FocusPanel(panel);
initWidget(focusPanel);
}
I delegate the implementation of the Focusable
and HasFocusHandlers
in the focus panel, e.g:
@Override
public void setFocus(boolean focused) {
focusPanel.setFocus(focused);
}
@Override
public void setTabIndex(int index) {
focusPanel.setTabIndex(index);
}
@Override
public HandlerRegistration addFocusHandler(FocusHandler handler) {
return focusPanel.addFocusHandler(handler);
}
And after that I can use setFocus(true)
to set the focus in any of my objects, and setTabIndex()
to set the tab index. Tab key also works as expected, but my problem is that I cannot handle focus events as the onFocus()
method of the handlers added with addFocusHandler()
are never called.
I know that the focus is changing because I follow the focus of the objets changing its style with :focus
CSS selector.
Why are focus handlers never called?