开发者

Client Browser detection in Vaadin

I want to set different themes to my Vaadin application, depending on the user agent. In particular I want to d开发者_运维知识库istinguish at least between mobile devices (iPhone, Android,...) and desktop web browser.

Vaadin's API reveals two interesting classes:

  • BrowserInfo
  • WebBrowser

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?


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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜