Maybe you can give the Tags (currentUser.getTags()) to the view, so
that the view is responsible for creating checkboxes or whatever, so
the presenter does not have to deal with widgets.
the view can map each Tab to the created Checkbox (to avoid the for-
loop) und call a method like tagChanged(Tag) in the presenter whenever
a checkbox is clicked

On 20 Sep., 03:18, Sydney <sydney.henr...@gmail.com> wrote:
> 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.

Reply via email to