Friday, July 30, 2010

Re: Can Gin inject eventBus into a widget that's created from uiBinder?

Inject your eventBus in to the widget, it will work just fine, then "new" your widget or create it by using injection, or whatever.

You only need <ui:with> if you need to access some object in the ui.xml file that you want to be constructed somewhere else. Typically this is some object that get injected in to the ui.xml associated .java class or it is a Resources object (typically also injected).

Example:

public class MyWidget extends Composite {
  private static MyWidgetUiBinder uiBinder = GWT.create(MyWidgetBinder.class);
  interface MyWidgetUiBinder extends UiBinder<Widget, MyWidget> {
  }

  private final EventBus bus;

  @UiField
  private HTMLPanel outerPanel;

  @Inject
  public MyWidget(EventBus bus) {
    this.bus = bus;
    initWidget(uiBinder.createAndBindUi(this));
  }

}

Dave

On Fri, Jul 30, 2010 at 3:08 PM, PeteUK <newbarker@gmail.com> wrote:
Hello,

I have a class called Mailboxes that derives from Composite. (This
widget contains a tree control to allow the user to select the mail
folder to view).

The Mailboxes instance is created by uiBinder within another widget
called Shortcuts. Here is the fragment of the Shortcuts.ui.xml file
that shows Mailboxes being created:

 <g:stack>
   <g:header size='3'>Mailboxes</g:header>
   <mail:Mailboxes ui:field='mailboxes'/>
 </g:stack>

What I've shown so far is from Google's sample Mail application. I
want to dependency inject the event bus into this instance. What is
the best way of doing this? I wasn't sure if Gin could do it because
GWT.create() is used within uiBinder to create the instance. I'm not
sure if I would even need Gin for this? I tried to see if ui:with
might help me but I haven't figured out how to use that properly yet
(very steep learning curve at the moment and I can't take much more
info at this stage!).

Thanks,

Pete

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
David Grant
http://www.davidgrant.ca

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment