Sunday, January 30, 2011

Spring ROO GWT with GIN injection on widgets created by ui:binder.

Hi, I'm not sure if this is the right place to post this, but I need
help getting GWT components to work inside the ROO generated scaffold.

In short, I create a new ROO project, eventually run GWT setup and
then try to add my own component using the suggested MVP.

Let's call the component Ror for the sake of the example and strip out
the code that's not relevant:

[CODE]
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:ig='urn:import:com.ig.client.scaffold.ui.widget'>

<ui:style>
</ui:style>

<g:HorizontalPanel>
<g:Button ui:field='myButton'>myButton</g:Button>
<g:Button ui:field='yourButton'>yourButton</g:Button>
</g:HorizontalPanel>
</ui:UiBinder>
[/CODE]

[CODE]
package com.ig.client.scaffold.ui.widget;

public class RorView extends Composite implements RorPresenter.Display
{

interface Binder extends UiBinder<Widget, RorView> {}
private static Binder BINDER = GWT.create(Binder.class);

@UiField Button myButton;
@UiField Button yourButton;

private ClickHandler myButtonClickHandler;
private ClickHandler yourButtonClickHandler;

public RorView(){
initWidget(BINDER.createAndBindUi(this));
}

@UiHandler("myButton")
void onMyButtonClick(ClickEvent event){
this.myButtonClickHandler.onClick(event);
}

@UiHandler("yourButton")
void onYourButtonClick(ClickEvent event){
this.yourButtonClickHandler.onClick(event);
}

@Override
public void setMyButtonClickHandler(ClickHandler
buttonClickHandler) {
this.myButtonClickHandler = buttonClickHandler;
}

@Override
public void setYourButtonClickHandler(ClickHandler
buttonClickHandler) {
this.yourButtonClickHandler = buttonClickHandler;
}

}
[/CODE]

[CODE]
public class RorPresenter {

package com.ig.client.scaffold.ui.widget;
//--------------------------------------------------------------------
public interface Display extends IsWidget {
void setMyButtonClickHandler(ClickHandler buttonClickHandler);
void setYourButtonClickHandler(ClickHandler
buttonClickHandler);
}
//--------------------------------------------------------------------

private final Display display;
private final EventBus eventBus;

@Inject
public RorPresenter(Display display, EventBus eventBus){
this.display = display;
this.eventBus = eventBus;
bind();
}

private void bind(){

display.setMyButtonClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("FIT");
}
});

display.setYourButtonClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("CIT");
}
});
}
}
[/CODE]

This Ror component is then added onto the default view
(ScaffoldDesktopShell.ui.xml) and for it to work, the view and
presenter layers need to be binded.

Inside ScaffoldModule (com.ig.client.scaffold.ioc) I add my binding
code ...
[CODE]
public class ScaffoldModule extends AbstractGinModule {

@Override
protected void configure() {

bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);

bind(ApplicationRequestFactory.class).toProvider(RequestFactoryProvider.class).in(Singleton.class);

bind(PlaceController.class).toProvider(PlaceControllerProvider.class).in(Singleton.class);

bind(RorPresenter.Display.class).to(RorView.class);
}
...
[/CODE]

... yet the binding doesn't appear to be working, the
myButtonClickHandler and yourButtonClickHandler inside the @UiHandler
s are null giving me a null pointer exception when I click on either
of the buttons.

Any idea what might be wrong with the binding code or why it's not
working? What I actually want to be doing is injecting an eventBus and
let the buttons fire an event on the event bus, but need to get the
binding to work first.

--
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