In the link, you've provided, there is a simple reason, why the view extends the HasValue interface. The view is a list of selectable items and if one item is selected, it should fire a ValueChangedEvent, so the presenter has to add a ValueChandEventHandler to the view. If your view doesn't fire any ValueChandedEvent, it shouldn't extend HasValue interface. Instead it could e. g. extend HasWidgets interface, to provide methods for adding Widgets.
The reason for decoupling this through such interfaces is, you can provide a dummy implementation of your view in a unit test. This allows you to test most of your code (except the view classes) with plain JUnit or TestNG, instead of using the slow GWTTestCase, which requires to run in special environment ( a headless hosted mode). Regards Jan Ehrhardt On Fri, Dec 25, 2009 at 3:18 PM, Abdullah Shaikh < [email protected]> wrote: > Hi All, > > I have gone through > http://code.google.com/webtoolkit/doc/latest/tutorial/mvp-architecture.html, > but while implementing the code I am bit confused. > > I have GwtApp as EntryPoint, this will initialise AppController and call > go(), and AppController in turn based on value (string) in onValueChange > create the presenter, I have fired valuechange by History.newItem("main"), > so that the AppPresenter is created first, which has AppView as View, but > the view is asking me to implement addValueChangeHandler because the Display > extends HasValue<String> as per the link above. > > Below is the code : > > 1) GwtApp: > > public class GwtApp implements EntryPoint { > public void onModuleLoad() { > AppController appViewer = new AppController(); > appViewer.go(RootPanel.get()); > } > } > > > > 2) AppController : > > public class AppController implements ValueChangeHandler<String> { > > private HasWidgets container = null; > HandlerManager eventBus = new HandlerManager(null); > > private void bind() { > History.addValueChangeHandler(this); > } > > public void go(final HasWidgets container) { > this.container = container; > > if ("".equals(History.getToken())) { > History.newItem("main"); > } > else { > History.fireCurrentHistoryState(); > } > } > > public void onValueChange(ValueChangeEvent<String> event) { > String token = event.getValue(); > > if (token != null) { > > Presenter presenter = null; > > if (token.equals("main")) { > presenter = new AppPresenter(new AppView(), eventBus); > } > > //add more presenters here based upon the token. > > if (presenter != null) { > //presenter.go(container); > } > } > } > > } > > > > 3) AppPresenter : > > public class AppPresenter implements Presenter { > > private AppPresenter.Display display = null; > > public interface Display extends HasValue<String> { > public HasClickHandlers getLogin(); > public Widget asWidget(); > } > > public void bind() { > display.getLogin().addClickHandler(new ClickHandler() { > > @Override > public void onClick(ClickEvent event) { > eventBus.fireEvent(new LoginClickEvent()); > } > }); > } > > public net.customware.gwt.presenter.client.Display getDisplay() { > return null; > } > > public void revealDisplay() {} > public void unbind() { } > public void refreshDisplay() { } > } > > > 4) AppView : > > public class AppView extends Composite implements AppPresenter.Display { > > private final Button login; > > public AppView() { > login = new Button("Login"); > } > > public HasClickHandlers getLogin() { > return login; > } > > public Widget asWidget() { > return this; > } > } > > > > Let me know where am I going wrong ? I think AppPresenter / AppView to be > the display of the initial application page using other Presenters. > > > Thanks, > Abdullah > > -- > 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.
