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

0 comments:

Post a Comment