aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/application/application-overview.asciidoc
blob: 0e653da9bdc186148ecc387902a14e3b6ad756ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
---
title: Overview
order: 1
layout: page
---

[[application.overview]]
= Overview

A Vaadin Framework application runs as a Java Servlet in a servlet container.
The Java Servlet API is, however, hidden behind the framework. The user
interface of the application is implemented as a __UI__ class, which needs to
create and manage the user interface components that make up the user interface.
User input is handled with event listeners, although it is also possible to bind
the user interface components directly to data. The visual style of the
application is defined in themes as CSS or Sass. Icons, other images, and
downloadable files are handled as __resources__, which can be external or served
by the application server or the application itself.

[[figure.application.architecture]]
.Vaadin Framework Application Architecture
image::img/application-architecture.png[width=75%, scaledwidth=90%]

<<figure.application.architecture>> illustrates the basic architecture of an
application made with the Vaadin Framework, with all the major elements, which
are introduced below and discussed in detail in this chapter.

First of all, a Vaadin Framework application must have one or more UI classes that extend
the abstract [classname]#com.vaadin.ui.UI# class and implement the
[methodname]#init()# method. A custom theme can be defined as an annotation for
the UI.


[source, java]
----
@Theme("hellotheme")
public class HelloWorld extends UI {
    protected void init(VaadinRequest request) {
        ... initialization code goes here ...
    }
}
----

A UI is a viewport to the application running in a web page. A web page can
actually have multiple such UIs within it. Such situation is typical especially
with portlets in a portal. An application can run in multiple browser windows,
each having a distinct [classname]#UI# instance. The UIs of an application can
be the same UI class or different.

Vaadin Framework handles servlet requests internally and associates the requests
with user sessions and a UI state. Because of this, you can develop
applications with Vaadin Framework much like you would develop desktop applications.

The most important task in the initialization is the creation of the initial
user interface. This, and the deployment of a UI as a Java Servlet in the
Servlet container, as described in
<<dummy/../../../framework/application/application-environment#application.environment,"Deploying
an Application">>, are the minimal requirements for an application.

Below is a short overview of the other basic elements of an application besides
UI:

UI:: A __UI__ represents an HTML fragment in which a Vaadin application runs in a web
page. It typically fills the entire page, but can also be just a part of a page.
You normally develop an application with Vaadin Framework by extending the [classname]#UI# class
and adding content to it. A UI is essentially a viewport connected to a user
session of an application, and you can have many such views, especially in a
multi-window application. Normally, when the user opens a new page with the URL
of the UI, a new [classname]#UI# (and the associated [classname]#Page#
object) is automatically created for it. All of them share the same user
session.

+
The current UI object can be accessed globally with
[methodname]#UI.getCurrent()#. The static method returns the thread-local UI
instance for the currently processed request
ifdef::web[]
 (see
<<dummy/../../../framework/advanced/advanced-global#advanced.global.threadlocal,"ThreadLocal
Pattern">>)
endif::web[]
.

Page:: A [classname]#UI# is associated with a [classname]#Page# object that represents
the web page as well as the browser window in which the UI runs.

+
The [classname]#Page# object for the currently processed request can be accessed
globally from a Vaadin application with [methodname]#Page.getCurrent()#. This is
equivalent to calling [methodname]#UI.getCurrent().getPage()#.

Vaadin Session:: A [classname]#VaadinSession# object represents a user session with one or more
UIs open in the application. A session starts when a user first opens a UI of a
Vaadin application, and closes when the session expires in the server or when it
is closed explicitly.

User Interface Components:: The user interface consists of components that are created by the application.
They are laid out hierarchically using special __layout components__, with a
content root layout at the top of the hierarchy. User interaction with the
components causes __events__ related to the component, which the application can
handle. __Field components__ are intended for inputting values and can be
directly bound to data using the data model of the framework. You can make your own user
interface components through either inheritance or composition. For a thorough
reference of user interface components, see
<<dummy/../../../framework/components/components-overview.asciidoc#components.overview,"User
Interface Components">>, for layout components, see
<<dummy/../../../framework/layout/layout-overview.asciidoc#layout.overview,"Managing
Layout">>, and for compositing components, see
<<dummy/../../../framework/components/components-customcomponent#components.customcomponent,"Composition
with Composite and CustomComponent">>.

Events and Listeners:: Vaadin Framework follows an event-driven programming paradigm, in which events, and
listeners that handle the events, are the basis of handling user interaction in
an application (although also server push is possible as described in
<<dummy/../../../framework/advanced/advanced-push#advanced.push,"Server
Push">>).
<<dummy/../../../framework/architecture/architecture-events#architecture.events,"Events
and Listeners">> gave an introduction to events and listeners from an
architectural point-of-view, while
<<dummy/../../../framework/application/application-events#application.events,"Handling
Events with Listeners">> later in this chapter takes a more practical view.

Resources:: A user interface can display images or have links to web pages or downloadable
documents. These are handled as __resources__, which can be external or provided
by the web server or the application itself.
<<dummy/../../../framework/application/application-resources#application.resources,"Images
and Other Resources">> gives a practical overview of the different types of
resources.

Themes:: The presentation and logic of the user interface are separated. While the UI
logic is handled as Java code, the presentation is defined in __themes__ as CSS
or SCSS. Vaadin includes some built-in themes. User-defined themes can, in
addition to style sheets, include HTML templates that define custom layouts and
other theme resources, such as images. Themes are discussed in detail in
<<dummy/../../../framework/themes/themes-overview.asciidoc#themes.overview,"Themes">>,
custom layouts in
<<dummy/../../../framework/layout/layout-customlayout#layout.customlayout,"Custom
Layouts">>, and theme resources in
<<dummy/../../../framework/application/application-resources#application.resources.theme,"Theme
Resources">>.

Data Binding:: With data binding, any field component in Vaadin Framework can be bound to the properties
of business objects such as JavaBeans and grouped together as forms. The components
can get their values from and update user input to the data model directly, without
the need for any control code. Similarly, any select component can be bound to a
__data provider__, fetching its items from a Java Collection or a backend such as an SQL database.
For a complete overview of data binding in Vaadin, please refer to
<<dummy/../../../framework/datamodel/datamodel-overview.asciidoc#datamodel.overview,"Binding
Components to Data">>.
ode that it affects, via a `jump' menu (and in the speedbar and Classes menu for JDE users). </para> </listitem> <listitem> <para> Source code annotation of inter-type and advice declarations, as well as the code they affect. </para> </listitem> <listitem> <para> AspectJ-style compilation, using .lst files to generate a compilation submenu. </para> </listitem> <listitem> <para> Highlighting of AspectJ keywords and declaration names. </para> </listitem> </itemizedlist> </para> <para> The first two are derived from ajc's last build of the AspectJ program. An example usage is given below. </para> <para> <inlinemediaobject id="aspectjmodescreenshot"> <imageobject> <imagedata fileref="aspectj-mode.gif"/> </imageobject> </inlinemediaobject> </para> </refsect1> <refsect1 id="ajmode-featuresandusage"><!-- Features and Usage --> <title>Features and Usage</title> <para> All commands governing AspectJ mode are available from the AspectJ menu on the toolbar. Besides those described below, there is a menu item <guimenuitem>Customize options</guimenuitem> for viewing and customizing the options of the mode and <guimenuitem>AJ Mode user guide</guimenuitem> to view this file. Keyword and declaration highlighting is enabled above the minimal level of highlighting. </para> <para> By default, AspectJ mode is automatically turned on when a buffer named with a <filename>.java</filename> suffix is entered. The command <command>M-x aspectj-mode-in-force-toggle</command> globally toggles the features of the mode, easing quickly moving between AspectJ and Java projects (also available as <guimenuitem>AspectJ mode extensions</guimenuitem> in the AspectJ menu). </para> <refsect2> <title>Aspect Structure and Navigation</title> <para> AspectJ minor mode highlights aspect relationships in the text with textual annotations on the program source (optionally can be turned off), such as the <literal>[Player, Robot, Ship]</literal> marking after the advice in EnsureShipIsAlive at the bottom of the <link linkend="aspectjmodescreenshot">figure</link>, which indicates that the advice refers to join points within Ship objects. The following commands (also available from the menu) manage annotations and navigation: </para> <table id="minormodecommands"> <title> AspectJ Minor Mode Commands for Annotations and Navigation </title> <tgroup cols="2" colsep="1" rowsep="1" align="left"> <thead> <row> <entry>Command (keyboard shortcut)</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry>M-x aspectj-jump-menu (C-x C-j)</entry> <entry> Display popup menu of advisers, advisees, and inter-type declarations. Navigate to item by selecting with mouse (see <link linkend="aspectjmodescreenshot2">figure</link> below). </entry> </row> <row> <entry>M-x aspectj-show-annotations</entry> <entry> Add crosscut annotations on the text on current buffer. </entry> </row> <row> <entry>M-x aspectj-dont-show-annotations</entry> <entry> Remove crosscut annotations from text on current buffer. </entry> </row> </tbody> </tgroup> </table> <para> The default for whether annotations are shown or not can be customized by selecting <guimenuitem>Customize options</guimenuitem> from the <guimenu>AspectJ</guimenu> menu. </para> <para> <inlinemediaobject id="aspectjmodescreenshot2"> <imageobject> <imagedata fileref="aspectj-mode2.gif"/> </imageobject> </inlinemediaobject> </para> </refsect2> <refsect2> <title>Compilation</title> <para> The <guisubmenu>Compile</guisubmenu> submenu accessible from the <guimenu>AspectJ</guimenu> menu presents the known<filename> .lst</filename> files for the project. Selecting one compiles the project with that <filename>.lst</filename> file and remembers that for future compiles. The <guimenuitem>Compile...</guimenuitem> command accessible from the Emacs <guimenu>Tools</guimenu> menu is customized through the project customization option <option>Aspectj Tools Compile Command</option>, customizable from the <guimenu>AspectJ</guimenu> menu. </para> </refsect2> </refsect1> <refsect1 id="ajmode-installationetc"><!-- Installation and Compatibility --> <title>Installation and Compatibility</title> <para> AspectJ mode requires the installation of <ulink url="http://www.gnu.org/software/emacs/">GNU Emacs 20.3.1</ulink> or <ulink url="http://www.xemacs.org/">XEmacs 21.1.14 (Unix/Linux)</ulink>, or <ulink url="http://www.xemacs.org/">XEmacs 21.4 (Windows)</ulink>, or higher. In general, the most recent non-alpha/beta versions of these are recommended. A web browser is required to view this documentation via Emacs. Small modifications to the <filename>.emacs</filename> file configures AspectJ mode and enables autoloading AspectJ mode when a <filename>.java</filename> file is loaded. </para> <refsect2> <title> Installation </title> <!-- <note> --> <para> Step 1, with enhancements, can be found in the example Emacs initialization file <filename>sample.emacs</filename> in the distribution. </para> <!-- </note> --> <orderedlist> <listitem> <para> The files in this package need to be in the load-path and ``required''. For example, for the 1.0 release: <programlisting> ;; I keep my emacs packages in C:/Emacs (setq load-path (cons "C:/Emacs/aspectj-emacsMode-1.0" load-path)) (require 'aspectj-mode)</programlisting> </para> </listitem> <listitem> <para> <emphasis>[Optional]</emphasis> add <literal>-emacssym</literal> switch to the <filename>ajc</filename> and <filename>ajc.bat</filename> files in your AspectJ tools installations (in the <filename>/bin</filename> directory). If you invoke the compiler outside Emacs, this will ensure that your compiles always generate information for annotations and the jump menu in the form of <literal>.ajesym</literal> files. </para> </listitem> <listitem> <para> <!-- TBD: Change to something less bogus. --> <emphasis>[XEmacs only]</emphasis> Go to the <filename>xemacs-packages/lisp</filename> directory of your XEmacs distribution and move the <filename>jde</filename> directory to someplace harmless. Otherwise, Java files will come up in JDE mode. </para> </listitem> </orderedlist> </refsect2> <refsect2> <title>Customizing Options</title> <para> Selecting <guimenuitem>Customize options</guimenuitem> from the <guimenu>AspectJ</guimenu> menu displays a number of options that customize AspectJ mode. These control whether annotations are shown by default, as well as a number of options controlling compilation and beanshell for java-mode. Example customizations are given in the file <filename>sample.emacs</filename> in the distribution. </para> </refsect2> </refsect1> <refsect1> <title>Usage and Upgrade Problems</title> <itemizedlist> <listitem> <para><emphasis>Symptom</emphasis>: No annotations show. Message: <screen> AspectJ Mode Warning: Can't find declarations file for... </screen> </para> <para>AspectJ file has not been compiled with ajc and the <literal>-emacssym</literal> flag, or was compiled with an obsolete version of ajc. After compilation, there should be a &lt;file&gt;.ajesym for every &lt;file&gt;.java in the build. If .ajsym files are present but error persists, recompile. Note that aspectj-mode for JDE has a fallback view for uncompiled files. </para> </listitem> <listitem> <para><emphasis>Symptom</emphasis>: Annotations are misplaced in the code. </para> <para>AspectJ mode operates by querying data derived from the most recent compile that includes the <literal>-emacssym</literal> flag. Recompile the entire program with ajc including the switch. Consider permanently installing the switch by editing the ajc and ajc.bat files in the /bin file in your distribution.</para> </listitem> <listitem> <para><emphasis>Symptom</emphasis>: New customization option settings were saved for future sessions, but do not show up when Emacs is restarted. </para> <para>You may have two sets of saved settings in your .emacs file, and Emacs updated the first one, which may be shadowed by the second.</para> </listitem> <listitem> <para><emphasis>Symptom</emphasis>: Java files that are part of a Java project not written in AspectJ come up in aspectj-mode. </para> <para>Emacs uses the file suffix (.java) to determine which mode to invoke. You can either globally toggle the AspectJ features from the AspectJ menu. </para> </listitem> <listitem> <para><emphasis>Symptom</emphasis>: Reported bug fixes and new features to aspectj-mode are not seen, or aspectj-mode.el cannot be found or loaded, with message: <screen> Error in init file: File error: "Cannot open load file", "aspectj-mode" </screen> </para> <para>Your load-path variable (set in your .emacs) is referring to an old release. Change your load-path to point at the directory for the current release. See the sample.emacs files in the distribution, for example.</para> </listitem> <listitem> <para><emphasis>Symptom</emphasis>: When trying to get a jump menu, I get the message "No crosscut elements at point" even though there is a [list] on the same line. </para> <para>The caret (point) is probably on or after the list. To see the crosscut elements you need to hit the jump menu on the same line that the annotated elements appear as a list of items surrounded by '[' and ']' on the same line as the affected declaration. If the caret is on the same line as the elements and before the list (i.e. not at the end of the list of elements) the jump menu should work. </para> </listitem> </itemizedlist> </refsect1> </refentry> <!-- Local variables: --> <!-- fill-column: 79 --> <!-- compile-command: "ant -quiet dev-html" --> <!-- sgml-local-ecat-files: devguide.ced --> <!-- sgml-parent-document:("devguide.sgml" "book" "refentry") --> <!-- End: -->