You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application-overview.asciidoc 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ---
  2. title: Overview
  3. order: 1
  4. layout: page
  5. ---
  6. [[application.overview]]
  7. = Overview
  8. A Vaadin Framework application runs as a Java Servlet in a servlet container.
  9. The Java Servlet API is, however, hidden behind the framework. The user
  10. interface of the application is implemented as a __UI__ class, which needs to
  11. create and manage the user interface components that make up the user interface.
  12. User input is handled with event listeners, although it is also possible to bind
  13. the user interface components directly to data. The visual style of the
  14. application is defined in themes as CSS or Sass. Icons, other images, and
  15. downloadable files are handled as __resources__, which can be external or served
  16. by the application server or the application itself.
  17. [[figure.application.architecture]]
  18. .Vaadin Framework Application Architecture
  19. image::img/application-architecture.png[width=75%, scaledwidth=90%]
  20. <<figure.application.architecture>> illustrates the basic architecture of an
  21. application made with the Vaadin Framework, with all the major elements, which
  22. are introduced below and discussed in detail in this chapter.
  23. First of all, a Vaadin Framework application must have one or more UI classes that extend
  24. the abstract [classname]#com.vaadin.ui.UI# class and implement the
  25. [methodname]#init()# method. A custom theme can be defined as an annotation for
  26. the UI.
  27. [source, java]
  28. ----
  29. @Theme("hellotheme")
  30. public class HelloWorld extends UI {
  31. protected void init(VaadinRequest request) {
  32. ... initialization code goes here ...
  33. }
  34. }
  35. ----
  36. A UI is a viewport to the application running in a web page. A web page can
  37. actually have multiple such UIs within it. Such situation is typical especially
  38. with portlets in a portal. An application can run in multiple browser windows,
  39. each having a distinct [classname]#UI# instance. The UIs of an application can
  40. be the same UI class or different.
  41. Vaadin Framework handles servlet requests internally and associates the requests
  42. with user sessions and a UI state. Because of this, you can develop
  43. applications with Vaadin Framework much like you would develop desktop applications.
  44. The most important task in the initialization is the creation of the initial
  45. user interface. This, and the deployment of a UI as a Java Servlet in the
  46. Servlet container, as described in
  47. <<application-environment#application.environment,"Deploying
  48. an Application">>, are the minimal requirements for an application.
  49. Below is a short overview of the other basic elements of an application besides
  50. UI:
  51. UI:: A __UI__ represents an HTML fragment in which a Vaadin application runs in a web
  52. page. It typically fills the entire page, but can also be just a part of a page.
  53. You normally develop an application with Vaadin Framework by extending the [classname]#UI# class
  54. and adding content to it. A UI is essentially a viewport connected to a user
  55. session of an application, and you can have many such views, especially in a
  56. multi-window application. Normally, when the user opens a new page with the URL
  57. of the UI, a new [classname]#UI# (and the associated [classname]#Page#
  58. object) is automatically created for it. All of them share the same user
  59. session.
  60. +
  61. The current UI object can be accessed globally with
  62. [methodname]#UI.getCurrent()#. The static method returns the thread-local UI
  63. instance for the currently processed request
  64. ifdef::web[]
  65. (see
  66. <<../advanced/advanced-global#advanced.global.threadlocal,"ThreadLocal
  67. Pattern">>)
  68. endif::web[]
  69. .
  70. Page:: A [classname]#UI# is associated with a [classname]#Page# object that represents
  71. the web page as well as the browser window in which the UI runs.
  72. +
  73. The [classname]#Page# object for the currently processed request can be accessed
  74. globally from a Vaadin application with [methodname]#Page.getCurrent()#. This is
  75. equivalent to calling [methodname]#UI.getCurrent().getPage()#.
  76. Vaadin Session:: A [classname]#VaadinSession# object represents a user session with one or more
  77. UIs open in the application. A session starts when a user first opens a UI of a
  78. Vaadin application, and closes when the session expires in the server or when it
  79. is closed explicitly.
  80. User Interface Components:: The user interface consists of components that are created by the application.
  81. They are laid out hierarchically using special __layout components__, with a
  82. content root layout at the top of the hierarchy. User interaction with the
  83. components causes __events__ related to the component, which the application can
  84. handle. __Field components__ are intended for inputting values and can be
  85. directly bound to data using the data model of the framework. You can make your own user
  86. interface components through either inheritance or composition. For a thorough
  87. reference of user interface components, see
  88. <<../components/components-overview.asciidoc#components.overview,"User
  89. Interface Components">>, for layout components, see
  90. <<../layout/layout-overview.asciidoc#layout.overview,"Managing
  91. Layout">>, and for compositing components, see
  92. <<../components/components-customcomponent#components.customcomponent,"Composition
  93. with Composite and CustomComponent">>.
  94. Events and Listeners:: Vaadin Framework follows an event-driven programming paradigm, in which events, and
  95. listeners that handle the events, are the basis of handling user interaction in
  96. an application (although also server push is possible as described in
  97. <<../advanced/advanced-push#advanced.push,"Server
  98. Push">>).
  99. <<../architecture/architecture-events#architecture.events,"Events
  100. and Listeners">> gave an introduction to events and listeners from an
  101. architectural point-of-view, while
  102. <<application-events#application.events,"Handling
  103. Events with Listeners">> later in this chapter takes a more practical view.
  104. Resources:: A user interface can display images or have links to web pages or downloadable
  105. documents. These are handled as __resources__, which can be external or provided
  106. by the web server or the application itself.
  107. <<application-resources#application.resources,"Images
  108. and Other Resources">> gives a practical overview of the different types of
  109. resources.
  110. Themes:: The presentation and logic of the user interface are separated. While the UI
  111. logic is handled as Java code, the presentation is defined in __themes__ as CSS
  112. or SCSS. Vaadin includes some built-in themes. User-defined themes can, in
  113. addition to style sheets, include HTML templates that define custom layouts and
  114. other theme resources, such as images. Themes are discussed in detail in
  115. <<../themes/themes-overview.asciidoc#themes.overview,"Themes">>,
  116. custom layouts in
  117. <<../layout/layout-customlayout#layout.customlayout,"Custom
  118. Layouts">>, and theme resources in
  119. <<application-resources#application.resources.theme,"Theme
  120. Resources">>.
  121. Data Binding:: With data binding, any field component in Vaadin Framework can be bound to the properties
  122. of business objects such as JavaBeans and grouped together as forms. The components
  123. can get their values from and update user input to the data model directly, without
  124. the need for any control code. Similarly, any select component can be bound to a
  125. __data provider__, fetching its items from a Java Collection or a backend such as an SQL database.
  126. For a complete overview of data binding in Vaadin, please refer to
  127. <<../datamodel/datamodel-overview.asciidoc#datamodel.overview,"Binding
  128. Components to Data">>.