Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
  • 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?
like image 494
Gerhard Dinhof Avatar asked Feb 02 '10 21:02

Gerhard Dinhof


People also ask

Is vaadin good?

Vaadin is a mature web framework for developing rich internet applications. Building web-based GUIs with Vaadin feels like developing a desktop application, which is great, comfortable and fast. However, there are situations where Vaadin is not suitable.

Is vaadin frontend or backend?

Vaadin is a full-stack web app platform. This means that, unlike React or Angular, Vaadin helps you with the backend of the application and makes it easier to coordinate frontend and backend work.

Is vaadin scalable?

Collaborative workplace web apps must typically accomodate hundreds, even thousands of concurrent users without putting a strain on the servers. Building your web app on Vaadin ensures your project a great starting point for scalability.


1 Answers

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();
}
like image 191
Gerhard Dinhof Avatar answered Sep 27 '22 21:09

Gerhard Dinhof