Application class

I have a quick question.
When I start my project with Root and mention that in the web.xml, what will happen to the Application instance. I did not understand it fully.
I started up an application by extending the Root class but still an Application instance is available. Who and at what point it gets instantiated? Also, how do we extend Application to add some functionality? For example, I want to add my own terminal error handler.

There is always an Application instance, created on the first request for something else than static resources. The Application is responsible for creating Roots as needed.

Referring to a root instead of an application in web.xml means that the default Application class is used. It simply creates roots based on what is given as the “root” parameter value in web.xml .

You can still use your own Application class - just continue to use “application” instead of or in addition to “root” in your web.xml . If you don’t need to override Root creation, use both parameters (“application” and “root”) in web.xml . If you do handle Root creation yourself, the “root” parameter is not needed.

Note that in any case, I would recommend placing UI code such as layouts in your Root class and only minimal functionality (creation of Root instances, management of application level state or data, terminal error handling etc.) in the Application.

And just to highlight a little more, with Vaadin 7 i haven’t yet needed an own Application class. I do all in Root and let Vaadin take care of Application itself.

Thanks

I would like to follow the approach you suggested. But, how can I plug-in my own terminal error handler to the application?

You could use Application.getCurrentApplication().setErrorHandler(…) if you don’t want to have your custom application class.

However, you should probably only set it once per application instance, and setting it from the Root might be too late for handling certain kinds of problems when selecting or initializing the Root.

There might be changes to these mechanisms in later Vaadin 7 alphas.

Thanks.