UI handling doubt in MVP

60 views
Skip to first unread message

Qrunk

unread,
Jan 13, 2012, 3:05:22 AM1/13/12
to google-we...@googlegroups.com
Hi ,

Im a bit confused as in what does UI handling is meant in http://code.google.com/webtoolkit/articles/mvp-architecture.html,  which is to be handled by the presenter.

Say I have a case where when I change my combo box , I want a UI widget(Text Box ) to be disabled. Now here there are two things:

1. I have to check through the data which I clicked inside the combo Box, which I believe should make my event to be handled by the presenter as my UI shouldn't be aware of my data part(Models)
2. As i want to make an UI related change in my page, this event should be handled by the View class.

Please let me know where and how should I delegate the event to event handlers on selection of the combo box item.
Should it be handled within Presenter, which cant happen because the presenter doesn't has any knowledge of the View component(in our case the Text Box that is to be disabled) or it should be handled within the View class, but this shouldn't happen as the View should be unaware of the Data part.and want some inputs on Request factory also
http://tbroyer.posterous.com/gwt-211-requestfactory-part-ii
 

Eric Metcalf

unread,
Jan 13, 2012, 1:32:47 PM1/13/12
to Google Web Toolkit
You want to put all of your logic into the presenter without putting
any of the widget code in that would prevent tests from running.

For the ListBox you want to declare a ChangeHandler on it in the
Presenter. To do that you have the View return back the ListBox as an
interface of HasChangeHandler.

@UiHandler ListBox fooItems;

public HasChangeHandler getHasChangeHandler() {
return fooItems;
}

You will also have to have the View return back the selected item
since I don't see any interfaces you can return to do that.

public String getItem() {
return fooItems.getItemText(fooItems.getSelectedIndex());
}

Finally the view can return back the TextBox has a HasEnabled
interface so the presenter can disable it.

@UiBinder TextBox textBox;

public HasEnabled getHasEnabled() {
return textBox;
}

Now the presenter can call these to get the item when selected and
disable the text box if needed.

view.getHasChangeHandler().addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
view.getItem();
view.getHasEnabled().setEnabled(false);
}
}
);



On Jan 13, 2:05 am, Qrunk <kapil2ka...@gmail.com> wrote:
> Hi ,
>
> Im a bit confused as in what does UI handling is meant inhttp://code.google.com/webtoolkit/articles/mvp-architecture.html,  which is

Thomas Broyer

unread,
Jan 14, 2012, 6:52:53 AM1/14/12
to google-we...@googlegroups.com


On Friday, January 13, 2012 9:05:22 AM UTC+1, Qrunk wrote:
Hi ,

Im a bit confused as in what does UI handling is meant in http://code.google.com/webtoolkit/articles/mvp-architecture.html,  which is to be handled by the presenter.

First: skip directly to the "part 2" article.

Say I have a case where when I change my combo box , I want a UI widget(Text Box ) to be disabled. Now here there are two things:

1. I have to check through the data which I clicked inside the combo Box, which I believe should make my event to be handled by the presenter as my UI shouldn't be aware of my data part(Models)

"my UI shouldn't be aware of my data part" is an anti-pattern; it implies too much abstractions, and leads to over-engineered and hard to maintain code.
 
2. As i want to make an UI related change in my page, this event should be handled by the View class.

Because it's related to your "presentation logic", it should go through to the presenter.

interface Presenter {
   void onSelectedXxxChanged(Xxx selectedItem);
}

interface View {
   void setYyyEnabled(boolean enabled);
}

Then in your presenter:
@Override
public void onSelectedXxxChanged(Xxx selectedItem) {
   boolean enabled = shouldEnableYyy(selectedItem); // your logic
   view.setYyyEnabled(enabled);
}

And in your view:

@UiField ValueListBox<Xxx> combo;
@UiFied TextBox yyy;

@UiHandler('combo")
void onComboValueChanged(ValueChangeEvent<Xxx> event) {
   presenter.onSelectedXxxChanged(event.getValue());
}

@Override
public void setYyyEnabled(boolean enabled) {
   yyy.setEnabled(enabled);
}

Please let me know where and how should I delegate the event to event handlers on selection of the combo box item.
Should it be handled within Presenter, which cant happen because the presenter doesn't has any knowledge of the View component(in our case the Text Box that is to be disabled) or it should be handled within the View class, but this shouldn't happen as the View should be unaware of the Data part.and want some inputs on Request factory also
http://tbroyer.posterous.com/gwt-211-requestfactory-part-ii

Whether you use RF or not doesn't change anything (using the Editor framework though blurs the line between presenter and view).

Qrunk

unread,
Jan 15, 2012, 1:37:14 AM1/15/12
to google-we...@googlegroups.com
thanks for the prompt replies ..... I think I got the perfect answers

Qrunk

unread,
Jan 15, 2012, 1:53:32 AM1/15/12
to google-we...@googlegroups.com
Hi,


"Using the Editor framework though blurs the line between presenter and view"
Can you please elaborate this and would be very useful if you do that using an example.

Thanks
Reply all
Reply to author
Forward
0 new messages