Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

There is an example in the gwt samples folder that does something like you are wanting. I use a version of the sample code in my project -except using Gin to handle the clientfactory functionality. The sample is called mobilewebapp. It involves using a formfactor method in your .gwt.xml to determine which system you are on - in this case it breaks it down into desktop, mobile, and tablet. Then later in your gwt.xml it trades out client factories based on the form factor - I trade out gin models instead. Here is a link to the source for mobilwebapp

Check the gwtp google group, its a good source, and someone posted a pdf about his efforts regarding the sake problem in there. Anyway, if I recall correctly, he holds multiple gin modules for each client with the presenters and views, runs custom js code on loading and than installs the correct module on the the ginClinet class.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top