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