Thursday, June 6, 2013

Vaadin 7 - Detect Browser


Case 1


in UI.init() you get the parameter VaadinRequest, which you can cast (after type check) to VaadinServletRequest and use the getHttpServletRequest to get the underlying HTTP request. This you can then use to check the "User-Agent". Something like:
if (request instanceof VaadinServletRequest) {
    HttpServletRequest httpRequest = ((VaadinServletRequest)request).getHttpServletRequest();
    String userAgent = httpRequest.getHeader("User-Agent").toLowerCase();

    // TODO: Check user agent for all tablet matching keywords
    if (userAgent.contains("ipad")) { 
        //...
    }

}
 

Case 2

public boolean isSmallScreenDevice() {
        float viewPortWidth = getUI().getWidth();
        return viewPortWidth < 600;
} 

Related Posts:

  • Vaadin 7 - Maven - Add widgetset and/or theme JAR to your classpath Eclipse Maven web application - can not run on server Right Click on your web project in Project Explorer -> select 'Properties'. Under project properties, select 'Deployment Assembly'. click 'Add' button, then se… Read More
  • Vaadin 7 - SCSS - Import Custom CSSInstead of a CSS file, provide a styles.scss file under /VAADIN/themes/<name> (in your case, the name is "custom"). The code below is just an example: 1 @import "../reindeer/styles.css"; 2 @import "../YOUR_… Read More
  • Vaadin - TouchKitCreating a Vaadin Touhckit Project with the Maven Archetype mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-touchkit -DarchetypeVersion=3.0.0-beta1 -DgroupId=org.configurator.mobil… Read More
  • Vaadin 7 - Detect Browser Case 1 in UI.init() you get the parameter VaadinRequest, which you can cast (after type check) to VaadinServletRequest and use the getHttpServletRequest to get the underlying HTTP request. This you can then use to chec… Read More

0 comments:

Post a Comment