|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vaadin.Application
public class Application
Base class required for all Vaadin applications. This class provides all the
basic services required by Vaadin. These services allow external discovery
and manipulation of the user, windows
and
themes, and starting and stopping the application.
As mentioned, all Vaadin applications must inherit this class. However, this
is almost all of what one needs to do to create a fully functional
application. The only thing a class inheriting the Application
needs to do is implement the init
method where it creates the
windows it needs to perform its function. Note that all applications must
have at least one window: the main window. The first unnamed window
constructed by an application automatically becomes the main window which
behaves just like other windows with one exception: when accessing windows
using URLs the main window corresponds to the application URL whereas other
windows correspond to a URL gotten by catenating the window's name to the
application URL.
See the class com.vaadin.demo.HelloWorld
for a simple example of
a fully working application.
Window access. Application
provides methods to
list, add and remove the windows it contains.
Execution control. This class includes method to start and finish the execution of the application. Being finished means basically that no windows will be available from the application anymore.
Theme selection. The theme selection process allows a theme
to be specified at three different levels. When a window's theme needs to be
found out, the window itself is queried for a preferred theme. If the window
does not prefer a specific theme, the application containing the window is
queried. If neither the application prefers a theme, the default theme for
the terminal
is used. The terminal
always defines a default theme.
Nested Class Summary | |
---|---|
class |
Application.ApplicationError
Application error is an error message defined on the application level. |
static class |
Application.ApplicationStartEvent
An event sent to start(ApplicationStartEvent) when a new
Application is being started. |
static class |
Application.CustomizedSystemMessages
Contains the system messages used to notify the user about various critical situations that can occur. |
static class |
Application.LegacyApplication
Deprecated. This class is only intended to ease migration and should not be used for new projects. |
static class |
Application.SystemMessages
Contains the system messages used to notify the user about various critical situations that can occur. |
class |
Application.UserChangeEvent
An event that characterizes a change in the current selection. |
static interface |
Application.UserChangeListener
The UserChangeListener interface for listening application
user changes. |
class |
Application.WindowAttachEvent
Window attach event. |
static interface |
Application.WindowAttachListener
Window attach listener interface. |
class |
Application.WindowDetachEvent
Window detach event. |
static interface |
Application.WindowDetachListener
Window detach listener interface. |
Field Summary | |
---|---|
static String |
ROOT_PARAMETER
The name of the parameter that is by default used in e.g. |
Constructor Summary | |
---|---|
Application()
|
Method Summary | |
---|---|
void |
addListener(Application.UserChangeListener listener)
Adds the user change listener. |
void |
addRequestHandler(RequestHandler handler)
Adds a request handler to this application. |
void |
addResource(ApplicationResource resource)
Adds new resource to the application. |
void |
close()
Ends the Application. |
String |
createConnectorId(ClientConnector connector)
Generate an id for the given Connector. |
ApplicationContext |
getContext()
Gets the application context. |
ConverterFactory |
getConverterFactory()
Gets the ConverterFactory used to locate a suitable
Converter for fields in the application. |
static Application |
getCurrent()
Gets the currently used application. |
Terminal.ErrorListener |
getErrorHandler()
Gets the application error handler. |
Locale |
getLocale()
Gets the default locale for this application. |
String |
getLogoutURL()
Returns the URL user is redirected to on application close. |
String |
getProperty(String name)
Searches for the property with the specified name in this application. |
Enumeration<?> |
getPropertyNames()
Returns an enumeration of all the names in this application. |
String |
getRelativeLocation(ApplicationResource resource)
Deprecated. this method is intended to be used by the terminal only. It may be removed or moved in the future. |
Collection<RequestHandler> |
getRequestHandlers()
Gets the request handlers that are registered to the application. |
ApplicationResource |
getResource(String key)
Find an application resource with a given key. |
protected Root |
getRoot(WrappedRequest request)
Gets a root for a request for which no root is already known. |
Root |
getRootById(int rootId)
Returns a Root with the given id. |
protected String |
getRootClassName(WrappedRequest request)
Provides the name of the Root class that should be used for
a request. |
Root |
getRootForRequest(WrappedRequest request)
Finds the Root to which a particular request belongs. |
Collection<Root> |
getRoots()
Gets all the roots of this application. |
static Application.SystemMessages |
getSystemMessages()
Gets the SystemMessages for this application. |
String |
getThemeForRoot(Root root)
Finds the theme to use for a specific root. |
URL |
getURL()
Gets the URL of the application. |
Object |
getUser()
Gets the user of the application. |
String |
getVersion()
Override this method to return correct version number of your Application. |
String |
getWidgetsetForRoot(Root root)
Finds the widgetset to use for a specific root. |
boolean |
handleRequest(WrappedRequest request,
WrappedResponse response)
Handles a request by passing it to each registered RequestHandler
in turn until one produces a response. |
void |
init()
Main initializer of the application. |
boolean |
isProductionMode()
Check whether this application is in production mode. |
boolean |
isRootInitPending(int rootId)
Checks whether there's a pending initialization for the root with the given id. |
boolean |
isRootPreserved()
Checks whether the same Root state should be reused if the framework can detect that the application is opened in a browser window where it has previously been open. |
boolean |
isRunning()
Tests if the application is running or if it has been finished. |
void |
removeListener(Application.UserChangeListener listener)
Removes the user change listener. |
void |
removeRequestHandler(RequestHandler handler)
Removes a request handler from the application. |
void |
removeResource(ApplicationResource resource)
Removes the resource from the application. |
void |
setConverterFactory(ConverterFactory converterFactory)
Sets the ConverterFactory used to locate a suitable
Converter for fields in the application. |
static void |
setCurrent(Application application)
Sets the thread local for the current application. |
void |
setErrorHandler(Terminal.ErrorListener errorHandler)
Sets the application error handler. |
void |
setLocale(Locale locale)
Sets the default locale for this application. |
void |
setLogoutURL(String logoutURL)
Sets the URL user is redirected to on application close. |
void |
setRootPreserved(boolean rootPreserved)
Sets whether the same Root state should be reused if the framework can detect that the application is opened in a browser window where it has previously been open. |
void |
setUser(Object user)
Sets the user of the application instance. |
void |
start(Application.ApplicationStartEvent event)
Starts the application on the given URL. |
void |
terminalError(Terminal.ErrorEvent event)
Invoked by the terminal on any exception that occurs in application and is thrown by the setVariable to the terminal. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ROOT_PARAMETER
Root
class.
Constructor Detail |
---|
public Application()
Method Detail |
---|
public Object getUser()
Vaadin doesn't define of use user object in any way - it only provides
this getter and setter methods for convenience. The user is any object
that has been stored to the application with setUser(Object)
.
public void setUser(Object user)
Sets the user of the application instance. An application instance may have a user associated to it. This can be set in login procedure or application initialization.
A component performing the user login procedure can assign the user property of the application and make the user object available to other components of the application.
Vaadin doesn't define of use user object in any way - it only provides
getter and setter methods for convenience. The user reference stored to
the application can be read with getUser()
.
user
- the new user.public URL getURL()
This is the URL what can be entered to a browser window to start the
application. Navigating to the application URL shows the main window (
#getMainWindow()
) of the application. Note that the main window
can also be shown by navigating to the window url (
com.vaadin.ui.Window#getURL()
).
public void close()
In effect this will cause the application stop returning any windows when
asked. When the application is closed, its state is removed from the
session and the browser window is redirected to the application logout
url set with setLogoutURL(String)
. If the logout url has not
been set, the browser window is reloaded and the application is
restarted.
public void start(Application.ApplicationStartEvent event)
This method is called by Vaadin framework when a user navigates to the application. After this call the application corresponds to the given URL and it will return windows when asked for them. There is no need to call this method directly.
Application properties are defined by servlet configuration object
ServletConfig
and they are overridden by
context-wide initialization parameters
ServletContext
.
event
- the application start event containing details required for
starting the application.public boolean isRunning()
Application starts running when its
#start(URL, Properties, ApplicationContext)
method has been
called and stops when the close()
is called.
true
if the application is running,
false
if not.public void init()
Main initializer of the application. The init
method is
called by the framework when the application is started, and it should
perform whatever initialization operations the application needs.
public Enumeration<?> getPropertyNames()
See #start(URL, Properties, ApplicationContext)
how properties
are defined.
public String getProperty(String name)
null
if the property is not found.
See #start(URL, Properties, ApplicationContext)
how properties
are defined.
name
- the name of the property.
public void addResource(ApplicationResource resource)
resource
- the resource to add.public void removeResource(ApplicationResource resource)
resource
- the resource to remove.@Deprecated public String getRelativeLocation(ApplicationResource resource)
resource
- the resource to get relative location.
public Locale getLocale()
public void setLocale(Locale locale)
locale
- the Locale object.public void addListener(Application.UserChangeListener listener)
setUser(Object)
is
called.
listener
- the user change listener to add.public void removeListener(Application.UserChangeListener listener)
listener
- the user change listener to remove.public String getLogoutURL()
null
, the application is closed normally as defined by the
application running environment.
Desktop application just closes the application window and web-application redirects the browser to application main URL.
public void setLogoutURL(String logoutURL)
null
, the application is closed normally as defined by the
application running environment: Desktop application just closes the
application window and web-application redirects the browser to
application main URL.
logoutURL
- the logoutURL to set.public static Application.SystemMessages getSystemMessages()
Application.CustomizedSystemMessages
. To "override" this method, re-implement
this method in your application (the class that extends
Application.LegacyApplication
). Even though overriding static methods is not
possible in Java, Vaadin selects to call the static method from the
subclass instead of the original getSystemMessages()
if such a
method exists.
public void terminalError(Terminal.ErrorEvent event)
Invoked by the terminal on any exception that occurs in application and
is thrown by the setVariable
to the terminal. The default
implementation sets the exceptions as ComponentErrors
to the
component that initiated the exception and prints stack trace to standard
error stream.
You can safely override this method in your application in order to direct the errors to some other destination (for example log).
terminalError
in interface Terminal.ErrorListener
event
- the change event.Terminal.ErrorListener.terminalError(com.vaadin.terminal.Terminal.ErrorEvent)
public ApplicationContext getContext()
The application context is the environment where the application is
running in. The actual implementation class of may contains quite a lot
more functionality than defined in the ApplicationContext
interface.
By default, when you are deploying your application to a servlet
container, the implementation class is WebApplicationContext
-
you can safely cast to this class and use the methods from there. When
you are deploying your application as a portlet, context implementation
is PortletApplicationContext
.
public String getVersion()
public Terminal.ErrorListener getErrorHandler()
public void setErrorHandler(Terminal.ErrorListener errorHandler)
errorHandler
- public ConverterFactory getConverterFactory()
ConverterFactory
used to locate a suitable
Converter
for fields in the application.
See setConverterFactory(ConverterFactory)
for more details
public void setConverterFactory(ConverterFactory converterFactory)
ConverterFactory
used to locate a suitable
Converter
for fields in the application.
The ConverterFactory
is used to find a suitable converter when
binding data to a UI component and the data type does not match the UI
component type, e.g. binding a Double to a TextField (which is based on a
String).
The Converter
for an individual field can be overridden using
AbstractField.setConverter(Converter)
and for individual property
ids in a Table
using
Table.setConverter(Object, Converter)
.
The converter factory must never be set to null.
converterFactory
- The converter factory used in the applicationprotected Root getRoot(WrappedRequest request) throws RootRequiresMoreInformationException
Subclasses of Application may override this method to provide custom logic for choosing how to create a suitable root or for picking an already created root. If an existing root is picked, care should be taken to avoid keeping the same root open in multiple browser windows, as that will cause the states to go out of sync.
If WrappedRequest.BrowserDetails
are required to create a Root, the
implementation can throw a RootRequiresMoreInformationException
exception. In this case, the framework will instruct the browser to send
the additional details, whereupon this method is invoked again with the
browser details present in the wrapped request. Throwing the exception if
the browser details are already available is not supported.
The default implementation in Application.LegacyApplication
creates a new instance
of the Root class returned by getRootClassName(WrappedRequest)
,
which in turn uses the "root" parameter from web.xml.
If DeploymentConfiguration.getClassLoader()
for the request
returns a ClassLoader
, it is used for loading the Root class.
Otherwise the ClassLoader
used to load this class is used.
request
- the wrapped request for which a root is needed
RootRequiresMoreInformationException
- may be thrown by an implementation to indicate that
WrappedRequest.BrowserDetails
are required to create a rootgetRootClassName(WrappedRequest)
,
Root
,
RootRequiresMoreInformationException
,
WrappedRequest.getBrowserDetails()
protected String getRootClassName(WrappedRequest request)
Root
class that should be used for
a request. The class must have an accessible no-args constructor.
The default implementation uses the "root" parameter from web.xml.
This method is mainly used by the default implementation of
getRoot(WrappedRequest)
. If you override that method with your
own functionality, the results of this method might not be used.
request
- the request for which a new root is required
public String getThemeForRoot(Root root)
null
is returned.
TODO Tell what the default implementation does once it does something.
root
- the root to get a theme for
null
if the default theme
should be usedpublic String getWidgetsetForRoot(Root root)
null
is returned.
TODO Tell what the default implementation does once it does something.
root
- the root to get a widgetset for
null
if the default
widgetset should be usedpublic boolean handleRequest(WrappedRequest request, WrappedResponse response) throws IOException
RequestHandler
in turn until one produces a response. This method is used for requests
that have not been handled by any specific functionality in the terminal
implementation (e.g. AbstractApplicationServlet
).
The request handlers are invoked in the revere order in which they were added to the application until a response has been produced. This means that the most recently added handler is used first and the first request handler that was added to the application is invoked towards the end unless any previous handler has already produced a response.
request
- the wrapped request to get information fromresponse
- the response to which data can be written
true
if a RequestHandler
has
produced a response and false
if no response has
been written.
IOException
addRequestHandler(RequestHandler)
,
RequestHandler
public void addRequestHandler(RequestHandler handler)
Handlers are called in reverse order of addition, so the most recently added handler will be called first.
handler
- the request handler to addhandleRequest(WrappedRequest, WrappedResponse)
,
removeRequestHandler(RequestHandler)
public void removeRequestHandler(RequestHandler handler)
handler
- the request handler to removepublic Collection<RequestHandler> getRequestHandlers()
handleRequest(WrappedRequest, WrappedResponse)
,
addRequestHandler(RequestHandler)
,
removeRequestHandler(RequestHandler)
public ApplicationResource getResource(String key)
key
- The key of the resource
null
if no resource is registered for the keypublic static Application getCurrent()
null
setCurrent(Application)
public static void setCurrent(Application application)
The application developer can also use this method to define the current application outside the normal request handling, e.g. when initiating custom background threads.
application
- getCurrent()
,
ThreadLocal
public boolean isProductionMode()
public Root getRootForRequest(WrappedRequest request) throws RootRequiresMoreInformationException
Root
to which a particular request belongs. If the
request originates from an existing Root, that root is returned. In other
cases, the method attempts to create and initialize a new root and might
throw a RootRequiresMoreInformationException
if all required
information is not available.
Please note that this method can also return a newly created
Root
which has not yet been initialized. You can use
isRootInitPending(int)
with the root's id (
Root.getRootId()
to check whether the initialization is still
pending.
request
- the request for which a root is desired
RootRequiresMoreInformationException
- if no existing root could be found and creating a new root
requires additional information from the browsergetRoot(WrappedRequest)
,
RootRequiresMoreInformationException
public void setRootPreserved(boolean rootPreserved)
NOTE that you should avoid turning this feature on/off on-the-fly when the UI is already shown, as it might not be retained as intended.
rootPreserved
- true
if the same Root instance should be reused
e.g. when the browser window is refreshed.public boolean isRootPreserved()
true
if the same Root instance should be reused e.g.
when the browser window is refreshed.public boolean isRootInitPending(int rootId)
rootId
- root id to check for
true
of the initialization is pending,
false
if the root id is not registered or if the
root has already been initializedgetRootForRequest(WrappedRequest)
public Collection<Root> getRoots()
public String createConnectorId(ClientConnector connector)
connector
- A connector that has not yet been assigned an id.
public Root getRootById(int rootId)
This is meant for framework internal use.
rootId
- The root id
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |