How to set a Presenter in a composite Widget?

61 views
Skip to first unread message

James Drinkard

unread,
Dec 20, 2011, 1:37:13 PM12/20/11
to Google Web Toolkit
Hello All,

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

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?

I know GIN would do it, but I'm not using that in the app as I've
never setup GIN with GWT. Any ideas as to the correct way to do this?

David

unread,
Dec 21, 2011, 9:53:51 AM12/21/11
to Google Web Toolkit

Many ways to do this. ViewImpl.ui.java will have a binding for the
composite widget
So you can simply pass the presenter or the instance of
ViewImpl.ui.java to the composite widget.

@UiField MyCompositeWidget theWidget;

.. theWidget.setParent(this)


Or you can use @UiField(provided=true) , @UiConstructor , or
@UiFactory.

see: http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html
Message has been deleted

James Drinkard

unread,
Dec 28, 2011, 12:13:48 PM12/28/11
to Google Web Toolkit
Would you show a fuller implementation for this?

On Dec 21, 8:53 am, David <levy...@gmail.com> wrote:
> Many  ways to do this.   ViewImpl.ui.java will have a binding  for the
> composite widget
> So you can simply pass the presenter or the instance of
> ViewImpl.ui.java to the composite widget.
>
> @UiField  MyCompositeWidget  theWidget;
>
> .. theWidget.setParent(this)
>
> Or you can use @UiField(provided=true)    ,  @UiConstructor ,  or
> @UiFactory.
>
> see:http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html
>

David

unread,
Dec 29, 2011, 11:10:34 AM12/29/11
to Google Web Toolkit

In your original thread you stated that you are calling
"nameView.setPresenter(this); ... "

If your implementation instance of nameView already has a handle to
your widget when calling setPresenter , then you can simply
change setPresenter to pass the presenter down to the widget.

...or you can try to use one of the techniques that I described in my
prior thread.

If that is still not clear then attach a zip of a trimmed done version
of your implementation and perhaps someone can point you in the right
direction.

James Drinkard

unread,
Dec 29, 2011, 4:47:27 PM12/29/11
to Google Web Toolkit
The way I did this was create a MUpld class with it's own ui.xml
file. Inside that class
I have a gwtUpload widget where I use @UiField and @UiHandler for the
Upload widget.
Then I reference the MUpld class as @UiField MUpld mUpld; in the
parent class: ViewImpl

In the ViewImpl class I use this code to define and set
the presenter, which is really an activity:

private Presenter presenter;
...
@Override
public void setPresenter(Presenter presenter)
{
this.presenter = presenter;
setMUpld(presenter);
}

So I have this working now, but I wasn't sure if it was proper GWT
coding as I keep
thinking somehow there is some mechanism in uiBinder I could use to
do
the same thing. The widget class: MUpld is a child of ViewImpl,
actually a
nested widget inside the ui.xml file of ViewImpl, so shouldn't it have
access to it's parent objects?

On Dec 29, 10:10 am, David <levy...@gmail.com> wrote:
> In your original thread you stated that you are calling
> "nameView.setPresenter(this); ... "
>
> If your implementation instance of nameView  already has a handle to
> your widget when calling  setPresenter , then you can simply
> change setPresenter to pass the presenter down to the widget.
>
> ...or you can try to use one of the techniques that I described in my
> prior thread.
>
> If that is still not clear then attach a zip of a trimmed done version
> of your implementation and perhaps someone can point you in the  right
> direction.
>
Reply all
Reply to author
Forward
0 new messages