On Sun, Jan 31, 2010 at 11:35 AM, Jethro Lai <jet...@jethrolai.com> wrote:

> I am new to this GWT MVP pattern even though I've been doing GWT for a
> while.
>
> Let me explain the problem I have. There is view in my application
> which is a list of words and the info within them.
> It's pretty much like the home page of UrbanDictionary. There are a
> list of words, and each word has much more info and UI components than
> ContactsView in Contacts example on Google's MVP tutorial page. My
> question is if we should not let View know about the data model, then
> how I can pass those info to this view


I'd really recommend adding gin to your toolkit. It'll make all this stuff
much easier.

Are you using the gwt-presenter framework? If so, inside your presenter:
display.addToList(word);



> and also I want to user to
> navigate to another view when they click word's title, and they can
> rate each word when they click thumb up or down.
>

So you want a sub-view? Create a "Rate This Word" event. Have a RateThisWord
presenter listen for the event and popup a RateThisWord view.


>
> So right now I have a DailyWordsView and DailyWordsPresenter. In this
> view, there should be couple items and each of them represents one
> word of a day.  Now there are two things I can do after I retrieve a
> list of word infos from server (List<DefinitionInfo>).
>
> 1, I can create a view for each DefinitionInfo and add it to
> DailyWordsView. So simply DailyWordsView is a vertical panel and
> couple WordOfDayViews reside in it.
>

No. Way too complicated. Keep the VerticalPanel and have your view add words
on request from your presenter.


> Two problems if I do this. One, there is no action I need from
> DailyWordsView, because all interactions I need are within each
> WordOfDayView. Two, when I pass a DefinitionInfo to a WordOfDayView,
> it doesn't attach to the view-does-not-know-data-model rule anymore.
> It's more coupled this way.
>
> 2, I can only have one view which is DailyWordsView, and awkwardly
> pass a list of lists of info,
> it could look something like:
>  void setData(ArrayList<Date> dates, ArrayList<String> titles,
>                                ArrayList<String> definers,
> ArrayList<String> contents,
>                                ArrayList<String> examples,
> ArrayList<Integer> rateUps,
>                                ArrayList<Integer> rateDowns);
>

I'd flatten this into a setData call inside an iterator over dates.
(for i = 0; i < dates.length(); i++) {
  setData(dates(i), titles(i), definers(i)...);
}

Somebody is going to have to iterate over those arrays. Your presenter knows
that they're arrays. Hide that info from the view; there's no reason it
needs to know those details.

and then create each item, but not new views, and add them to
> DailyWordsView. Now it becomes hard for me to keep track on which item
> is reacting to user's action. So I must have
> int getClickedRateUpId(ClickEvent event);
> int getClickedRateDownId(ClickEvent event);
> int getClickedTitleId(ClickEvent event);
> in my Display interface in DailyWordsView,
>

So? The event keeps track of the source of each event. You'd need those
events anyway. The events fire a message to the Presenter which then updates
the Model.


> and also keep the list of DefinitionInfo for the moment I fire an
> event.
>

In the presenter? That's correct.


> This is more decoupled but very awkward.
>

Probably not as awkward as you think, and definitely easier to test.

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

Reply via email to