简体   繁体   中英

GWT pattern for handling mobile browsers

I am working on a GWT app that needs to serve a different layout to mobile device users. I can easily determine if a user is using a mobile browser; however, I'm not sure about the best pattern for handling them.

I am currently using the MVP pattern - would it be best to simply pass a browser-specific view to the Presenter or is there a more appropriate method?

The way I've done it is to have different GWT modules (with their own entrypoint, Gin modules, even different CssResources) and then on the myapp.html page you just have to check out what browser is requesting the content and based on it (javascript checks) the appropriate module

<script src="myapp/myapp.nocache.js"/>

or

<script src="mymobileapp/mymobileapp.nocache.js"/>

is loaded.

If you are working with GIN and an MVP framework ( gwt-platform is my platform of choice) you can then reuse the code that was already written for the presenters and only implement different views.

You could set up GWT to detect the web browser used, as described in this question . Then, via Deferred Binding , let the compiler "slip" the correct view into place for the, say, mobilesafari user agent. That way, you won't have to litter your Java code with browser detection, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM