Passing an object to the constructor of a widget defined in uibinder

I am trying to pass my EventBus application to a widget declared in UiBinder through its constructor. I use the @UiConstructor annotation to indicate the constructor that accepts the EventBus, but I don't know how to actually refer to the object from my ui.xml code.

That is, I need something like

WidgetThatNeedsAnEventBus.java

public class WidgetThatNeedsAnEventBus extends Composite
{
    private EventBus eventBus;

    @UiConstructor
    public WidgetThatNeedsAnEventBus(EventBus eventBus)
    {
        this.eventBus = eventBus;
    }
}

TheUiBinderThatWillDeclareAWTNAEB.ui.xml

<g:HTMLPanel>
    <c:WidgetThatNeedsAnEventBus eventBus=_I_need_some_way_to_specify_my_apps_event_bus_ />
</g:HTMLPanel>

I have no problem passing a static value to WidgetThatNeedsAnEventBus, and I can use the factory method to create a new EventBus object. But I need to transfer my existing EventBus application.

Is there a way to reference existing objects in UiBinder?

+5
2

@UiField(provided=true) , .

Java, initWidget .

:

public class ParentWidget extends Composite
{
    @UiField(provided=true)
    protected ChildWidget child;

    public ParentWidget(Object theObjectIWantToPass)
    {
        child = new ChildWidget(theObjectIWantToPass);  //_before_ initWidget
        initWidget(uiBinder.create(this));

        //proceed with normal initialization!
    }
}
+8

factory ( ). .

<ui:with> ( , setter) ( ). GWT.create, , , , eventBus.

+2

All Articles