How can I access WebBrowser class?

On my application I need to access user’s WebBrowser class. Is this missing from the API or known restriction??

Thanks

Neither, just simply do

WebBrowser browser = (WebBrowser) myApplication.getMainWindow().getTerminal();

Why we must do casting? Internally IT Mill Toolkit supports many kinds of terminals. Just imagine casting Terminal to SymbianPhone and asking it to callTo(‘+35822394309’).

Back to web. You can easily look for many kinds of aspects (automatically detected) from your browser: IT Mill Ltd is now Vaadin Ltd

Ok, but this gives me an exception. I still need to do choiches depending what kind of terminal is connecting to my application and I an doing this check on the first page. WebBrowser object is null on first click that user makes. How can I fix this?

Yes this is the class I need to use but cannot use on first request.

Here is my code sample taken from your hello demo. Please have a look.


    public void init() {
        Window main = new Window("Hello window");
        setMainWindow(main);
        main.addComponent(new Label("Hello World!"));
        WebBrowser wb = (WebBrowser) main.getTerminal();
        main.addComponent(new Label("My terminal is "+wb));
        // here I need to do decisions based on terminal, but it is null!!
    }   

This shows at screen:


Hello World! 
My terminal is null 

You are right. At the application init the terminal has not yet been set. Although you can probably design your application in a way that it only inspects Browser class in some later stage, I would consider this to be a bug (should be fixed in 4.0.1).

But you can access WebBrowser through Paintable.Paint method. WebBrowser is initialized properly after this point. Not elegant solution but should provide you an workaround. So, create your frontpage as e.g. CustomComponent and override Paint method like:


public void paint(PaintTarget target) throws PaintException {
  WebBroser webBrowser = (WebBrowser) getWindow().getTerminal();
  // use webBrowser as needed..
  // remember to call super's paint
  super.paint(target);
}

This still hasn’t been fixed in 6.7.4. It would be very nice if this was fixed. I have an app that needs to know so that it can layout. I tried delaying initialisation, but it wasn’t a success.

In Vaadin 7, it will be possible to have this information available at initialization time (with the framework using an extra client-server roundtrip before application initialization when necessary).
With Vaadin 6, the information will only be available when also the client side part of the application has been initialized.

FYI: the current solution for this is: Page.getCurrent().getWebBrowser()