Vaadin 中的客户端浏览器检测

发布于 2024-08-20 05:09:43 字数 781 浏览 8 评论 0原文

我想根据用户代理为我的 Vaadin 应用程序设置不同的主题。 我特别想至少区分移动设备(iPhone、Android...)和桌面网络浏览器。

Vaadin 的 API 揭示了两个有趣的类:

BrowserInfo 似乎可以完成这项工作完全满足我的需求,但通过其 get 方法实例化失败:

SEVERE: javax.servlet.ServletException: ...
Caused by: java.lang.UnsatisfiedLinkError: com.vaadin.terminal.gwt.client.BrowserInfo.getBrowserString()Ljava/lang/String;

也无法找到从我的应用程序内访问 WebBrowser 的方法。

  1. 我是否选择了正确的浏览器区分方法?
  2. 为什么访问 BrowserInfo 失败?

I want to set different themes to my Vaadin application, depending on the user agent.
In particular I want to distinguish at least between mobile devices (iPhone, Android,...) and desktop web browser.

Vaadin's API reveals two interesting classes:

BrowserInfo seems to do the job perfectly for my needs, but fails on instancing via its get-method:

SEVERE: javax.servlet.ServletException: ...
Caused by: java.lang.UnsatisfiedLinkError: com.vaadin.terminal.gwt.client.BrowserInfo.getBrowserString()Ljava/lang/String;

Couldn't find a way to access WebBrowser from within my application either.

  1. Did I choose the right approach for browser distinction?
  2. Why does accessing BrowserInfo fail?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒芜了季节 2024-08-27 05:09:43

正如@quickanalysis 所指出的,您必须意识到客户端/服务器端组件的分离。

为了在服务器端获取用户代理字符串,以下代码片段可以完成这项工作:

ApplicationContext context = this.getContext();
if (context instanceof WebApplicationContext) {
   String userAgent = ((WebApplicationContext)this.getContext()).
getBrowser().getBrowserApplication();
}

As @quickanalysis pointed out, you've to be aware of the separation of client-/server-side components.

For getting the user agent string on server-side, the following code snippet does the job:

ApplicationContext context = this.getContext();
if (context instanceof WebApplicationContext) {
   String userAgent = ((WebApplicationContext)this.getContext()).
getBrowser().getBrowserApplication();
}
月下伊人醉 2024-08-27 05:09:43

您试图从哪个类调用此方法? BrowserInfo 在客户端可用,而 WebBrowser 在服务器端可用。看一下包的命名。

From what class you are trying to call this method? The BrowserInfo is available at client-side as WebBrowser ar the server-side. Take a look at the package naming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文