English 中文(简体)
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 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?
最佳回答

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.





相关问题
Destroying session on close of the browser from the task bar

When I close the browser window from the task bar the session is not getting destroyed. I could handle this on closing the browser using close(X) button or by pressing Alt+F4 using javascript. But ...

InvokeMethod not working on windows form

I have a windows form containing a webbrowser that navigates to a site which sends data back in the form of a table. I would like to transfer the data on that table to a application that runs some ...

Automated web browser?

For learning purposes I would like to automate some parts in a browser game, currently I am trying to fill out some simple text boxes, without any luck though. I ve created a WebBrowser component on ...

MySQL - Username to connect using Query browser

I m fairly new to my sql, and I need to know what is the default username for mysql, like in mssql you have sa . I can connect to the mysql command client but it does not ask me for a username.

Widescreen check on normal screen

I work normal screen and I develop some web application. When the application goes on widescreen some of the pages looks weired. Is there any way I can view my web page as it looks in Widescreen on my ...

How does Google get a toolbar right below the tabs in IE?

I researched through all BHO related documentation, but I just can t figure how Google gets the translation toolbar right below the tabs in IE. Any useful pointers how to achieve the same effect for ...

How to detect page zoom level in all modern browsers?

How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can t find a good cross-browser solution. Firefox stores the page zoom level for ...

热门标签