MVP Question.

4 views
Skip to first unread message

nacho

unread,
Jul 11, 2010, 2:50:31 PM7/11/10
to Google Web Toolkit
Hi, i'm trying to make a view like the following that i paste. But i
need to add click handlers to the links in the presenter. How could i
do. I was looking the method getClickedCell in the mvp presentation
but the problem is that my links are inside a FlowPanel that is inside
a Vertical that is inside a Cell.

What i need to do is to fire an event when the links are clicked, for
example, when i press in the View link i need to populate the
pnlCategoryImages with the result of my rpc.

The only thing that i figure to do is to call the event bus from the
view itself, but it doesn't look so pretty.

Anyone have some ideas?

This is part of my code in the setData() method.

for(Category category: categories){
int tblCategoriesNumRow = tblCategories.getRowCount();

VerticalPanel pnlCategory = new VerticalPanel();

Hyperlink lnkAdd = new Hyperlink("Add", "");
Hyperlink lnkRemove = new Hyperlink("Remove", "");
Hyperlink lnkView = new Hyperlink("View", "");

FlowPanel pnlCategoryButtons = new FlowPanel();
pnlCategoryButtons.add(lnkAdd);
pnlCategoryButtons.add(lnkRemove);
pnlCategoryButtons.add(lnkView);
pnlCategory.add(pnlCategoryButtons);

tblCategories.setWidget(tblCategoriesNumRow, 0, chkCategory);
tblCategories.setWidget(tblCategoriesNumRow, 1, pnlCategory);

tblCategoriesNumRow = tblCategories.getRowCount();

ScrollPanel pnlCategoryImages = new ScrollPanel();
tblCategories.setWidget(tblCategoriesNumRow, 0, pnlCategoryImages);
}
...

Gal Dolber

unread,
Jul 11, 2010, 3:15:00 PM7/11/10
to google-we...@googlegroups.com
try something like this from the presenter:

view.setHandler(ViewHandler handler);

interface ViewHandler {

void onView(Category c);
void onRemove(Category c);

}

whatever any one say to you, DO NOT USE GETTERS ON THE VIEW INTERFACE :)

2010/7/11 nacho <vela.i...@gmail.com>

--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
http://gwtupdates.blogspot.com/

nacho

unread,
Jul 11, 2010, 4:47:57 PM7/11/10
to Google Web Toolkit
I think that from that handler i should call the eventBus in the
onView and onRemove methods, right?

But how do i connect every link to that handler? Should i put a
onClickHandler on every lnk that i create in the view that calls those
methods?

Sorry if i am saying stupid things, i' am newby to mvp model :)

On 11 jul, 16:15, Gal Dolber <gal.dol...@gmail.com> wrote:
> try something like this from the presenter:
>
> view.setHandler(ViewHandler handler);
>
> interface ViewHandler {
>
> void onView(Category c);
> void onRemove(Category c);
>
> }
>
> whatever any one say to you, DO NOT USE GETTERS ON THE VIEW INTERFACE :)
>
> 2010/7/11 nacho <vela.igna...@gmail.com>
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsu...@googlegroups.com>
> > .

Gal Dolber

unread,
Jul 11, 2010, 7:10:28 PM7/11/10
to google-we...@googlegroups.com
There no right or wrong way to implement MVP, its just a pattern and you can implement it as you like. The only points I think are important are:
  • (As I already said) The view interface shouldn't have getters. This makes mocking easy peasy.
  • Do not handle Widgets on the presenter (any widget code makes your presenter no longer testeable). This means that the methods on the ViewHandlers shouldn't have widget type parameters
  • Do not abuse of Event bus, at least I try no to do it.. in general if you need to notice one presenter only of an event find the way to get a reference to it. Try to use eventbus only when you need more than one presenters to handle that event.

Just implement that handlers in the presenter.
class YourPresenter implements YourViewHandler {
void onView(Category c) { 
//HERE YOUR CODE
}
void onRemove(Category c) { 
//HERE YOUR CODE
}

// In the constructor: view.setHandlers(this);

}

And in the view add a click handler to each hyperlink and trigger the viewhandler method

In the view you are right, you just add a click handler to each Hyperlink and trigger the method of the handler.

2010/7/11 nacho <vela.i...@gmail.com>
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages