Sunday, September 19, 2010

Re: MVP pattern and dynamic widgets

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

No comments:

Post a Comment