简体   繁体   English

用于处理移动浏览器的GWT模式

[英]GWT pattern for handling mobile browsers

I am working on a GWT app that needs to serve a different layout to mobile device users. 我正在开发一个GWT应用程序,需要为移动设备用户提供不同的布局。 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? 我目前正在使用MVP模式 - 最好是简单地将特定于浏览器的视图传递给Presenter,还是有更合适的方法?

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 我这样做的方法是拥有不同的GWT模块(有自己的入口点,Gin模块,甚至不同的CssResources)然后在myapp.html页面上你只需要查看哪些浏览器正在请求内容并基于它(javascript检查)相应的模块

<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. 如果您正在使用GIN和MVP框架( gwt-platform是我选择的平台),那么您可以重用已经为演示者编写的代码,并且只实现不同的视图。

You could set up GWT to detect the web browser used, as described in this question . 您可以设置GWT来检测所使用的Web浏览器, 如此问题中所述 Then, via Deferred Binding , let the compiler "slip" the correct view into place for the, say, mobilesafari user agent. 然后,通过Deferred Binding ,让编译器将正确的视图“滑动”到例如mobilesafari用户代理。 That way, you won't have to litter your Java code with browser detection, etc. 这样,您就不必在浏览器检测等情况下乱丢Java代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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