Search code examples
gwtmvpgwt-mvpgwt-platformgwtp

Implementing multiple views via GWT-platform?


I'm implementing a web application which will support different views according to different browsers. For example, In mobile browsers, it will show a smaller view to users with less UI elements. But we'd like to use same presenters.

I have a solution on hand - adding browser type detecting logic in ClientModule, e.g:

if (browser == "iphone") {
    bindPresenter(HomePresenter.class, HomePresenter.MyView.class, HomeView.class, HomePresenter.MyProxy.class);
} else if (browser == "ipad") {
    bindPresenter(HomePresenter.class, HomePresenter.MyView.class, IPadHomeView.class, HomePresenter.MyProxy.class);
} else {
    bindPresenter(HomePresenter.class, HomePresenter.MyView.class, IPhoneHomeView.class, HomePresenter.MyProxy.class);
}

I'm wondering if it is possible to use some ways like deferred binding in GWT-platform. (but I'd like to follow GWT-plarform's structure rather than adding deferred binding code in xxx.gwt.xml).

So my questions are:

1) Are there any other ways to implement the feature mentioned above?
2) Which way is the best, and why?

Thanks in advance!

Best regards,
Jiakuan W


Solution

  • GWT does not allow you to set custom user agent types. You're limited to their set of gecko, gecko1_7, safari, IE6, IE7, IE8, and opera.

    That being said, you can access the user agent directly and set your logic to switch accordingly with Window.Navigator.getUserAgent(), or via a property provider.

    See this similar question on how to do mobile browser detection in GWT for MVP.