Pregunta

I have a GWT 2.4 app using MVP, clientFactory, activities, places, and uiBinder. I have a composite widget that I created as a standalone object with it's own ui.xml file. I reference that class and insert it into the main viewImpl.ui.xml file.

The composite widget receives some data from the backend and I need to get it back to the activity so it can be displayed in a table. I'm using the presenter that is associated with the view to get to the activity. Here is the code: In the View interface:

public interface NameView extends IsWidget
{
    void setPresenter(Presenter presenter);
...    

public interface Presenter{
            void goTo(Place place);
            void setRowDataList(List<Data> rowData);
        }

In my Activity I implement the View.Presenter as in:

 Activity extends AbstractActivity implements NameView.Presenter

so the activity is the presenter I need from within my standalone widget and in the start method for the activity I use:

NameView  nameView = clientFactory.getNameView();//NameView is just an example.
nameView.setPresenter(this); ...

to setup the presenter and instantiate it. My problem is, in the widget I need this:

presenter.setRowDataList(rowData);

but I'm not sure how to reference the instantiated Presenter from the widget?

This separate widget, actually a gwtUpload widget, is standalone. I do a server side calculation on some data that is uploaded and that is what is returned back to this widget.

The widget data needs to get back to the Activity in order to pass that data back to the NameViewImpl class.

I thought the presenter was the proper way to do that, but since the widget isn't wired to the view or viewImpl I need a way to get that presenter for the widget.

I know GIN would do it with DI or maybe I create another presenter. I've never setup GIN with GWT. Any ideas as to the correct way to do this?

Working Implementation:

I don't know if this is the best implementation or not, but based on the answer from Thomas, I set my widget with the instance of the presenter(activity) in the setPresenter() method in the ViewImpl class. It works as a pass-through for the widget to return back to the activity. I assume that is what Thomas meant as a callback interface.

¿Fue útil?

Solución

What we did in similar situations is to define a callback interface for the widget (similar to the presenter interface in your presenter-view pair), and then we generally make the presenter interface extend that widget-specific interface.
Then, when we call setPresenter (or whatever it's called) on the view, to associated the presenter, the view immediately calls setCallback on the widget with the same value (the presenter implements the callback interface).

An alternative design is to hide the widget-specific callback behind a method of your presenter interface. Let the view implement the callback, implementing the method such that it's routed to the equivalent method of the presenter.

BTW, GIN won't help here.

Otros consejos

If I understand you right, you have one set of objects activity, presenter and ui (the NameView) and another object separated from these three. The separated object is gwtUpload widget.

One way to notify the presenter is by using the eventBus. I'm sure you have reference in the activity. For the gwtUpload I do not know what exactly you mean by 'standalone' object, you must have some kind a connection to a other presenter to reach the eventBus.

The gwtUpload widget will fire an event(through it's own presenter) in the eventBus with the result from the server side calculations. Keep in mind that it is good practice to send only model objects as result. The activity will "register" a handler on the eventBus for the event. In the handler you can send the data to the view in order to update the table display.

I do not think you need GIN to resolve this, for any case here is good tutorial for start: http://code.google.com/p/google-gin/wiki/GinTutorial

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top