@daniel

I created the map but how do you register the value change handler on
the checkboxes? Do you do it in the view or in the presenter? My guess
is that it must be done in the presenter but how do you get a
reference to the checkboxes?

I was thinking of adding these methods in the view.

// Same as before but with Map creation
public void initTagsContainer(List<Tag> tags) {
        map = new HashMap<Tag, CheckBox>
        tagsContainer.clear();
        for (Tag tag : tags) {
        CheckBox checkbox = new CheckBox(tag.getTagName());
            tagsContainer.add(checkbox);
            map.put(tag, checkbox);
        }
}

public List<HasValueChangeHandlers<Boolean>> getTagsCheckBoxes() {
  List<HasValueChangeHandlers<Boolean>> handlers = new
ArrayList<HasValueChangeHandlers<Boolean>>();
  for(Tag key:map.keySet()) {
    handlers.add(map.get(key));
  }
  return handlers;
}

@cyij

Your approach is good. I might use it but before I want to see how I
can avoid the loop like daniel suggested.

On Sep 19, 10:01 pm, احمد عبدلله <gass...@gmail.com> wrote:
> 2010/9/19, Sydney <sydney.henr...@gmail.com>:
>
>
>
> > 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 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.

-- 
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