Get screen resolution

I do so

WebApplicationContext context = ((WebApplicationContext) this.getContext());
WebBrowser webBrowser = context.getBrowser();

result
webBrowser.getAddress() - ok
webBrowser.getBrowserApplication() - ok
webBrowser.getScreenHeight() - only 0
webBrowser.getScreenWidth() - only 0

Do you do this in application init? I know that some of the information are not avaiable at that point.

public class MCS extends com.vaadin.Application {

    final Window main = new Window("");

    @Override
    public void init () {
        if (this.ipFilter()) {
            this.start();
        } else {
            this.ban();
        }
    }

 public void start () {
        setMainWindow(main);
}

private boolean ipFilter () {

        WebApplicationContext context = ((WebApplicationContext) this.getContext());
        WebBrowser webBrowser = context.getBrowser();

        String[] ip_access = {"127.0.0.1",
                             "192.168.1.100",
                             "192.168.1.101",
                             "192.168.1.102"};

        return filter(webBrowser.getAddress(), ip_access);
    }

    private boolean filter (String title, String[] patterns) {
        try {
            for (String s : patterns) {
                if (-1 != title.indexOf(s)) {
                    return true;
                }
            }
        } catch (NullPointerException e) {
        }
        return false;
    }

Well, how do I get the screen resolution?

Delay it until after init()

can example?
something is not working

This is how i do

[font=Courier New]

  1. let you Application implements HttpServletRequestListener
  2. // use this method to persist user details (log or db?)
    public void onRequestStart(HttpServletRequest request, HttpServletResponse response)
    {
    if (getContext() == null)
    return;
    if (getMainWindow().getBrowserWindowWidth() <=0)
    return;
    WebBrowser browser = ((com.vaadin.terminal.gwt.server.WebApplicationContext)getContext()).getBrowser();
    if (!isPrinted) {
    printDetails(browser);
    isPrinted = true;
    }
    if (browser.getScreenHeight() == screenHeight || browser.getScreenWidth() == screenWidth)
    return;
    screenHeight = browser.getScreenHeight();
    screenWidth = browser.getScreenWidth();
    logger.info(“********* Client Screen is " + browser.getScreenWidth() + " x " + browser.getScreenHeight() + " *********”);
    }
  3. private void printDetails(WebBrowser browser) {
    String browserName = browser.isIE() ? “Internet Explorer” : browser.isFirefox() ? “FireFox” : browser.isChrome() ? “Chrome” : browser.isSafari() ? “Safari” : browser.isOpera() ? “Opera” : “Unknown”;
    String version = browser.getBrowserMajorVersion() + “.” + browser.getBrowserMinorVersion();
    String os = browser.isWindows() ? “Windows” : browser.isLinux() ? “Linux” : browser.isMacOSX() ? “MacOS” : “Unknown”;
    String ipAddress = browser.getAddress();
    logger.info( String.format(“\nBrowser is %s - %s \nOS is %s\nIP is %s\nCurrent Date is %s\nScreen Resolution is %s\nIs Touch enabled? %s\nLocale - %s\nTimezone offset - %s DaylightSaving - %s. DST is %s”, browserName, version, os, ipAddress, browser.getCurrentDate(), (browser.getScreenWidth() + " x " + browser.getScreenHeight()), browser.isTouchDevice(), browser.getLocale(),getHourMinute(browser.getRawTimezoneOffset()), getHourMinute(browser.getDSTSavings()), (!browser.isDSTInEffect() ? "NOT " : “”) + “in effect”));
    System.out.println("Browser is " + browserName + " - " + version);
    System.out.println("OS is " + os);
    System.out.println("IP is " + ipAddress);
    System.out.println("Current Date is " + browser.getCurrentDate());
    System.out.println("Screen Resolution is - " + browser.getScreenWidth() + " x " + browser.getScreenHeight() );
    System.out.println("Client Area is - " + getMainWindow().getBrowserWindowWidth() + " x " + getMainWindow().getBrowserWindowHeight() );
    System.out.println("is Touch enabled Device? " + browser.isTouchDevice());
    System.out.println("Locale - " + browser.getLocale());
    System.out.println("Timezone Offset " + getHourMinute(browser.getRawTimezoneOffset()) + " DayLightSaving " + getHourMinute(browser.getDSTSavings()) + ". DST is " + (!browser.isDSTInEffect() ? "NOT " : “”) + “in effect”);
    }
    [/font]

it work!