ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 01.01.2026
Просмотров: 2545
Скачиваний: 0
Book of Vaadin
Vaadin 7 Edition
Book of Vaadin: Vaadin 7 Edition
Vaadin Ltd
Marko Grönroos
Vaadin 7 Edition Edition
Vaadin Framework 7.0.0
Published: 2013-03-04
Copyright © 2000-2013 Vaadin Ltd
Abstract
Vaadin is an AJAX web application development framework that enables developers to build high-quality user interfaces with Java, both on the serverand client-side. It provides a set of libraries of ready-to-use user interface components and a clean framework for creating your own components. The focus is on ease- of-use, re-usability, extensibility, and meeting the requirements of large enterprise applications.
All rights reserved. This work is licensed under the Creative Commons CC-BY-ND License Version 2.0
[http://creativecommons.org/licenses/by-nd/2.0/legalcode].
Table of Contents |
|
Preface .......................................................................................................................... |
xiii |
Part I. Introduction ........................................................................................................... |
19 |
Chapter 1. Introduction ......................................................................................... |
21 |
1.1. Overview .................................................................................................. |
21 |
1.2. Example Application Walkthrough .............................................................. |
23 |
1.3. Support for the Eclipse IDE ....................................................................... |
24 |
1.4. Goals and Philosophy ............................................................................... |
25 |
1.5. Background .............................................................................................. |
25 |
Chapter 2. Getting Started with Vaadin .................................................................. |
27 |
2.1. Overview .................................................................................................. |
27 |
2.2. Setting up the Development Environment ................................................... |
28 |
2.2.1. Installing Java SDK ........................................................................ |
29 |
2.2.2. Installing Eclipse IDE ...................................................................... |
30 |
2.2.3. Installing Apache Tomcat ................................................................ |
31 |
2.2.4. Firefox and Firebug ........................................................................ |
31 |
2.3. Overview of Vaadin Libraries ..................................................................... |
32 |
2.4. Installing Vaadin Plugin for Eclipse ............................................................. |
33 |
2.4.1. Installing the IvyDE Plugin .............................................................. |
33 |
2.4.2. Installing the Vaadin Plugin ............................................................. |
34 |
2.4.3. Updating the Plugins ...................................................................... |
36 |
2.4.4. Updating the Vaadin Libraries ......................................................... |
36 |
2.5. Creating and Running a Project with Eclipse ............................................... |
36 |
2.5.1. Creating the Project ....................................................................... |
37 |
2.5.2. Exploring the Project ...................................................................... |
41 |
2.5.3. Coding Tips for Eclipse ................................................................... |
42 |
2.5.4. Setting Up and Starting the Web Server .......................................... |
44 |
2.5.5. Running and Debugging ................................................................. |
45 |
2.6. Using Vaadin with Maven ........................................................................... |
46 |
2.6.1. Working from Command-Line .......................................................... |
46 |
2.6.2. Compiling and Running the Application ........................................... |
47 |
2.6.3. Using Add-ons and Custom Widget Sets ......................................... |
48 |
2.7. Creating a Project with NetBeans IDE ........................................................ |
48 |
2.7.1. Maven Project from a Vaadin Archetype ........................................... |
48 |
2.7.2. Regular Web Application Project ..................................................... |
49 |
2.8. Vaadin Installation Package ....................................................................... |
49 |
2.8.1. Package Contents .......................................................................... |
49 |
2.8.2. Installing the Libraries .................................................................... |
50 |
Chapter 3. Architecture ......................................................................................... |
51 |
3.1. Overview .................................................................................................. |
51 |
3.2. Technological Background ......................................................................... |
54 |
3.2.1. HTML and JavaScript ..................................................................... |
54 |
3.2.2. Styling with CSS and Sass ............................................................. |
54 |
3.2.3. AJAX ............................................................................................. |
54 |
3.2.4. Google Web Toolkit ........................................................................ |
55 |
3.2.5. Java Servlets ................................................................................. |
55 |
3.3. Client-Side Engine .................................................................................... |
56 |
3.4. Events and Listeners ................................................................................. |
57 |
Part II. Server-Side Framework ........................................................................................ |
59 |
Book of Vaadin |
i |
Book of Vaadin
Chapter 4. Writing a Server-Side Web Application ................................................. |
61 |
4.1. Overview .................................................................................................. |
61 |
4.2. Building the UI .......................................................................................... |
64 |
4.2.1. Application Architecture .................................................................. |
65 |
4.2.2. Compositing Components ............................................................... |
66 |
4.2.3. View Navigation ............................................................................. |
67 |
4.2.4. Layered Architectures ..................................................................... |
67 |
4.2.5. Accessing UI, Page, Session, and Service ....................................... |
68 |
4.3. Handling Events with Listeners .................................................................. |
68 |
4.3.1. Implementing a Listener in a Regular Class ..................................... |
69 |
4.3.2. Differentiating Between Event Sources ............................................ |
69 |
4.3.3. The Easy Way: Using Anonymous Classes ...................................... |
70 |
4.4. Images and Other Resources .................................................................... |
70 |
4.4.1. Resource Interfaces and Classes .................................................... |
71 |
4.4.2. File Resources ............................................................................... |
71 |
4.4.3. Class Loader Resources ................................................................ |
72 |
4.4.4. Theme Resources .......................................................................... |
72 |
4.4.5. Stream Resources ......................................................................... |
73 |
4.5. Handling Errors ......................................................................................... |
74 |
4.5.1. Error Indicator and message ........................................................... |
74 |
4.5.2. Customizing System Messages ...................................................... |
74 |
4.5.3. Handling Uncaught Exceptions ...................................................... |
75 |
4.6. Notifications .............................................................................................. |
76 |
4.6.1. Notification Type ............................................................................. |
77 |
4.6.2. Customizing Notifications ............................................................... |
78 |
4.6.3. Styling with CSS ............................................................................ |
79 |
4.7. Application Lifecycle .................................................................................. |
79 |
4.7.1. Deployment ................................................................................... |
79 |
4.7.2. Vaadin Servlet, Portlet, and Service ................................................ |
80 |
4.7.3. User Session ................................................................................. |
80 |
4.7.4. Loading a UI .................................................................................. |
81 |
4.7.5. UI Expiration .................................................................................. |
82 |
4.7.6. Session Expiration ......................................................................... |
82 |
4.7.7. Closing a Session .......................................................................... |
82 |
4.8. Deploying an Application ........................................................................... |
83 |
4.8.1. Creating Deployable WAR in Eclipse ............................................... |
83 |
4.8.2. Web Application Contents ............................................................... |
83 |
4.8.3. Deployment Descriptor web.xml .................................................... |
84 |
4.8.4. Other Deployment Parameters ........................................................ |
85 |
4.8.5. Deployment Configuration .............................................................. |
87 |
Chapter 5. User Interface Components ................................................................. |
89 |
5.1. Overview .................................................................................................. |
90 |
5.2. Interfaces and Abstractions ....................................................................... |
91 |
5.2.1. Component Interface ..................................................................... |
92 |
5.2.2. AbstractComponent ..................................................................... |
93 |
5.2.3. Field Components (Field and AbstractField) .................................. |
93 |
5.3. Common Component Features .................................................................. |
96 |
5.3.1. Caption ......................................................................................... |
96 |
5.3.2. Description and Tooltips .................................................................. |
97 |
5.3.3. Enabled ......................................................................................... |
98 |
5.3.4. Icon ............................................................................................... |
99 |
5.3.5. Locale ......................................................................................... |
100 |
ii
Book of Vaadin
5.3.6. Read-Only ................................................................................... |
102 |
5.3.7. Style Name .................................................................................. |
103 |
5.3.8. Visible ......................................................................................... |
104 |
5.3.9. Sizing Components ...................................................................... |
104 |
5.3.10. Managing Input Focus ................................................................ |
106 |
5.4. Component Extensions ........................................................................... |
107 |
5.5. Label ..................................................................................................... |
107 |
5.5.1. Content Mode .............................................................................. |
108 |
5.5.2. Making Use of the HTML Mode ..................................................... |
109 |
5.5.3. Spacing with a Label .................................................................... |
109 |
5.5.4. CSS Style Rules .......................................................................... |
110 |
5.6. Link ....................................................................................................... |
110 |
5.7. TextField ............................................................................................... |
112 |
5.7.1. Data Binding ................................................................................ |
113 |
5.7.2. String Length ............................................................................... |
114 |
5.7.3. Handling Null Values .................................................................... |
114 |
5.7.4. Text Change Events ...................................................................... |
115 |
5.7.5. CSS Style Rules .......................................................................... |
116 |
5.8. TextArea ................................................................................................ |
116 |
5.9. PasswordField ....................................................................................... |
118 |
5.10. RichTextArea ....................................................................................... |
118 |
5.11. Date and Time Input with DateField ....................................................... |
120 |
5.11.1. PopupDateField ........................................................................ |
120 |
5.11.2. InlineDateField ......................................................................... |
123 |
5.11.3. Time Resolution ......................................................................... |
124 |
5.11.4. DateField Locale ........................................................................ |
125 |
5.12. Button ................................................................................................. |
125 |
5.13. CheckBox ............................................................................................ |
126 |
5.14. Selecting Items ..................................................................................... |
127 |
5.14.1. Binding Selection Components to Data ........................................ |
127 |
5.14.2. Basic Select Component ............................................................ |
131 |
5.14.3. ListSelect ................................................................................. |
133 |
5.14.4. Native Selection Component NativeSelect .................................. |
133 |
5.14.5. Radio Button and Check Box Groups with OptionGroup .............. |
134 |
5.14.6. Twin Column Selection with TwinColSelect ................................. |
136 |
5.14.7. Allowing Adding New Items ......................................................... |
137 |
5.14.8. Multiple Selection Mode .............................................................. |
138 |
5.14.9. Other Common Features ............................................................ |
139 |
5.15. Table .................................................................................................... |
139 |
5.15.1. Selecting Items in a Table ........................................................... |
141 |
5.15.2. Table Features ........................................................................... |
142 |
5.15.3. Editing the Values in a Table ........................................................ |
145 |
5.15.4. Column Headers and Footers ...................................................... |
149 |
5.15.5. Generated Table Columns ........................................................... |
150 |
5.15.6. Formatting Table Columns ........................................................... |
153 |
5.15.7. CSS Style Rules ......................................................................... |
154 |
5.16. Tree ..................................................................................................... |
157 |
5.17. MenuBar .............................................................................................. |
158 |
5.18. Embedded Resources ........................................................................... |
160 |
5.18.1. Embedded Image ...................................................................... |
160 |
5.18.2. Adobe Flash Graphics ................................................................ |
161 |
5.18.3. BrowserFrame .......................................................................... |
161 |
5.18.4. Generic Embedded Objects ....................................................... |
161 |
5.19. Upload ................................................................................................. |
162 |
iii
Book of Vaadin
5.20. ProgressIndicator ............................................................................... |
164 |
5.20.1. Doing Heavy Computation .......................................................... |
165 |
5.21. Slider ................................................................................................... |
166 |
5.22. Component Composition with CustomComponent ................................. |
168 |
5.23. Composite Fields with CustomField ...................................................... |
169 |
Chapter 6. Managing Layout ................................................................................ |
171 |
6.1. Overview ................................................................................................ |
173 |
6.2. Window and Panel Content ...................................................................... |
174 |
6.3. VerticalLayout and HorizontalLayout ..................................................... |
175 |
6.3.1. Sizing Contained Components ...................................................... |
175 |
6.4. GridLayout ............................................................................................ |
179 |
6.4.1. Sizing Grid Cells .......................................................................... |
180 |
6.5. FormLayout ........................................................................................... |
183 |
6.6. Panel ..................................................................................................... |
184 |
6.6.1. Scrolling the Panel Content ........................................................... |
185 |
6.7. Sub-Windows ......................................................................................... |
186 |
6.7.1. Opening and Closing a Sub-Window ............................................. |
187 |
6.7.2. Window Positioning ...................................................................... |
189 |
6.7.3. Scrolling Sub-Window Content ...................................................... |
189 |
6.7.4. Modal Windows ............................................................................ |
190 |
6.8. HorizontalSplitPanel and VerticalSplitPanel .......................................... |
190 |
6.9. TabSheet ............................................................................................... |
192 |
6.10. Accordion ............................................................................................ |
195 |
6.11. AbsoluteLayout ................................................................................... |
197 |
6.12. CssLayout ........................................................................................... |
199 |
6.13. Layout Formatting ................................................................................. |
202 |
6.13.1. Layout Size ................................................................................ |
202 |
6.13.2. Layout Cell Alignment ................................................................. |
203 |
6.13.3. Layout Cell Spacing .................................................................... |
205 |
6.13.4. Layout Margins ........................................................................... |
207 |
6.14. Custom Layouts .................................................................................... |
209 |
Chapter 7. Visual User Interface Design with Eclipse .......................................... |
211 |
7.1. Overview ................................................................................................ |
211 |
7.2. Creating a New Composite ...................................................................... |
212 |
7.3. Using The Visual Designer ....................................................................... |
214 |
7.3.1. Adding New Components ............................................................. |
215 |
7.3.2. Setting Component Properties ...................................................... |
216 |
7.3.3. Editing an AbsoluteLayout .......................................................... |
218 |
7.4. Structure of a Visually Editable Component .............................................. |
220 |
7.4.1. Sub-Component References ......................................................... |
220 |
7.4.2. Sub-Component Builders .............................................................. |
221 |
7.4.3. The Constructor ........................................................................... |
221 |
Chapter 8. Themes ............................................................................................... |
223 |
8.1. Overview ................................................................................................ |
223 |
8.2. Introduction to Cascading Style Sheets .................................................... |
225 |
8.2.1. Basic CSS Rules .......................................................................... |
225 |
8.2.2. Matching by Element Class ........................................................... |
226 |
8.2.3. Matching by Descendant Relationship ........................................... |
227 |
8.2.4. Notes on Compatibility .................................................................. |
230 |
8.3. Syntactically Awesome Stylesheets (Sass) ............................................... |
230 |
8.3.1. Sass Overview ............................................................................. |
231 |
8.3.2. Sass Basics with Vaadin ............................................................... |
231 |
iv
Book of Vaadin
8.3.3. Compiling On the Fly .................................................................... |
232 |
8.3.4. Compiling Sass to CSS ................................................................ |
232 |
8.4. Creating and Using Themes .................................................................... |
232 |
8.4.1. Sass Themes ............................................................................... |
232 |
8.4.2. Plain Old CSS Themes ................................................................. |
233 |
8.4.3. Styling Standard Components ....................................................... |
233 |
8.4.4. Built-in Themes ............................................................................ |
235 |
8.4.5. Using Themes in an UI ................................................................. |
236 |
8.4.6. Theme Inheritance ....................................................................... |
236 |
8.5. Creating a Theme in Eclipse .................................................................... |
236 |
Chapter 9. Binding Components to Data ............................................................. |
239 |
9.1. Overview ................................................................................................ |
239 |
9.2. Properties .............................................................................................. |
241 |
9.2.1. Property Viewers and Editors ........................................................ |
242 |
9.2.2. ObjectProperty Implementation ................................................... |
243 |
9.2.3. Converting Between Property Type and Representation .................. |
243 |
9.2.4. Implementing the Property Interface ............................................. |
245 |
9.3. Holding properties in Items ...................................................................... |
246 |
9.3.1. The PropertysetItem Implementation ........................................... |
247 |
9.3.2. Wrapping a Bean in a BeanItem ................................................... |
247 |
9.4. Creating Forms by Binding Fields to Items ................................................ |
249 |
9.4.1. Simple Binding ............................................................................. |
249 |
9.4.2. Using a FieldFactory to Build and Bind Fields ........................... |
250 |
9.4.3. Binding Member Fields ................................................................. |
250 |
9.4.4. Buffering Forms ........................................................................... |
251 |
9.4.5. Binding Fields to a Bean ............................................................... |
252 |
9.4.6. Bean Validation ............................................................................ |
252 |
9.5. Collecting Items in Containers .................................................................. |
254 |
9.5.1. Basic Use of Containers ............................................................... |
254 |
9.5.2. Container Subinterfaces ............................................................... |
255 |
9.5.3. IndexedContainer ....................................................................... |
256 |
9.5.4. BeanContainer ........................................................................... |
257 |
9.5.5. BeanItemContainer .................................................................... |
259 |
9.5.6. Iterating Over a Container ............................................................. |
260 |
9.5.7. Filterable Containers ................................................................... |
261 |
Chapter 10. Vaadin SQLContainer ....................................................................... |
265 |
10.1. Architecture .......................................................................................... |
266 |
10.2. Getting Started with SQLContainer ........................................................ |
266 |
10.2.1. Creating a connection pool .......................................................... |
266 |
10.2.2. Creating the TableQuery Query Delegate .................................... |
267 |
10.2.3. Creating the Container ................................................................ |
267 |
10.3. Filtering and Sorting .............................................................................. |
267 |
10.3.1. Filtering ..................................................................................... |
267 |
10.3.2. Sorting ...................................................................................... |
268 |
10.4. Editing .................................................................................................. |
268 |
10.4.1. Adding items .............................................................................. |
268 |
10.4.2. Fetching generated row keys ....................................................... |
268 |
10.4.3. Version column requirement ........................................................ |
269 |
10.4.4. Auto-commit mode ..................................................................... |
269 |
10.4.5. Modified state ............................................................................ |
269 |
10.5. Caching, Paging and Refreshing ............................................................ |
270 |
10.5.1. Container Size ........................................................................... |
270 |
v