3

I want to use the Editor Framework of GWT within my project.

In my View(which implements Editor) I have my UiBinder Field:

@UiField
TextBox text;

In my Presenter I inject via GIN the driver instance:

@Inject
public AppointmentPopupPresenter(EventBus eventBus, MyView view, final AppointmentDriver appointmentDriver)

When the presenter is called I try to initialize the driver with:

this.appointmentDriver.initialize(getView());
this.appointmentDriver.edit(new Appointment());

GINModule:

 bind(SimpleBeanEditorDriver.class).to(AppointmentDriver.class);

AppointmentDriver interface:

public interface AppointmentDriver extends SimpleBeanEditorDriver<Appointment, AppointmentPopupPresenter.MyView>{

}

Later when I listen to a button event I call:

appointmentDriver.flush();

but all properties are null and no error msg is thrown. If I look into the debugger into the textbox widget the instance of "editor" is null as well. dont know the internas but maybe this is a hint for you.

Appointment POJO(of course with void setText(String text)/String getText()):

 String text;

At the moment I am completely stuck so any help is more than welcome.

Thank you!!

Gambo
  • 1,572
  • 3
  • 26
  • 52

2 Answers2

1

I see you do a getView() , does it return the same view as the one passed to the constructor and the same as shown in the ui? It could be the driver is initialized with a different view than the one actual shown and thus you will get the data from the incorrect view. I also don't understand why you do the bind, it seems unnecessary?

Hilbrand Bouwkamp
  • 13,509
  • 1
  • 45
  • 52
  • Yes I looked at the debugger and its the correct view. if i change now my driver to the explict view instead of the view interface: public interface AppointmentDriver extends SimpleBeanEditorDriver{} and driver.initialize((AppointmentPopupView)getView()); its working. I really dont know why and I am feeling a little bit unconfortable with the cast in my presenter. Why is the bind unnecessary, i thought i need it later to inject it? – Gambo Aug 03 '11 at 21:52
  • I think I know what it is. Your driver should extend with `AppointmentPopupView` argument and not `MyView`. Because based on these arguments GWT generates driver code also your `AppointmentPopupView` should implement `Editor` because due to the way GWT works it needs the interface on each class that contains editor code otherwise it can't see the TextBox in te AppointmentPopupView. – Hilbrand Bouwkamp Aug 04 '11 at 10:45
  • Regarding the bind. I'm not to familiar with GIN, but as you use it, it looks to me it means that when `SimpleBeanEditorDriver` is used as argument the `AppointmentDriver` is injected. But in your code you use the `AppointmentDriver` directly and not the `SimpleBeanEditorDriver` so GIN inject doesn't `AppointmentDriver` instead and so no bind to is needed. – Hilbrand Bouwkamp Aug 04 '11 at 10:48
  • Hilbrand, thanks for your answer. This was excactly the issue. Regarding gin your are also right as it makes no sense at all to bind it with gin... – Gambo Aug 07 '11 at 12:38
0

I'm not sure, but I assume the problem is, that you're just calling SimpleBeanEditorDriver.initialize(E editor). As far as I remember, you need to call RequestFactoryEditorDriver.initialize(EventBus, RequestFactory, E)

Maybe my little (now updated for GWT 2.3, but still completely unpolished) example project can help you.

Here's the snippet where I make the initialize calls:

    final MyRequestFactory requestFactory = GWT
            .create(MyRequestFactory.class);
    requestFactory.initialize(eventBus);

    final MyEditor myEditor = new MyEditor();
    driver.initialize(eventBus, requestFactory, myEditor);

It should be possible to refactor the project to use GIN.

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • Thanks for your help, sadly I am not using the RequestFactory as I am building up my on json/rest service so I only need the editor stuff. Anyway I will have a look on your project! – Gambo Aug 02 '11 at 16:34