Recently we are learning the MVP pattern.

We think that the presenter don't need to know how the implementation of the
view, but the data which the view is need.

So, put the following code into the view will be better,
*
*
*// Build the UI in the fly*
*tagsContainer.clear();*
* for (Tag tag : currentUser.getTags()) {*
*  tagsContainer.add(new CheckBox(tag.getTagName()));*
* }*

*// Find the one which are checked*
* int i=0;*
* for(Tag tag: currentUser.getTags()) {*
*  boolean checked = getView().getCheckBox(i).getValue();*
*  i++;*
* }*

then provide two interfaces: *initTagsContainer(Tag tag)* and *
getSelectedTag().*

How about this approach?

My english is poor, and wish you can understand what i mean.

2010/9/20 Sydney <[email protected]>

> My question is related to the MVP pattern. I have a VerticalPanel in
> which I add several CheckBox. The UI is build on the fly since it
> depends on the user settings. The user clicks some of the checkboxes
> and in my presenter I would like to know which one are selected. What
> should I put in my view interface of the presenter. My current
> approach is the following:
>
> The presenter:
>
> public interface MyView {
>  HasWidgets getTagsContainer();
>  void showTagsContainer(); // Do a setVisible in the view
>  HasValue<Boolean> getCheckBox(int i); // Return the ith checkbox
> }
>
> // Build the UI in the fly
> HasWidgets tagsContainer = getView().getTagsContainer();
> tagsContainer.clear();
> for (Tag tag : currentUser.getTags()) {
>  tagsContainer.add(new CheckBox(tag.getTagName()));
> }
> getView().showTagsContainer();
>
> The user clicks on some of the checkboxes
>
> // Find the one which are checked
> int i=0;
> for(Tag tag: currentUser.getTags()) {
>  boolean checked = getView().getCheckBox(i).getValue();
>  i++;
> }
>
> What do you think of my approach? Is there a better way to achieve it?
> I am learning the MVP pattern, so I try to get the best practices.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
每天做好一件事

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to