ICT role in 21st century education and it's challenges.
Vaadin JPAContainer
1. Vaadin Data Model and
JPAContainer
YRD.DOÇ.DR. CELAL MURAT KANDEMİR
ESKİSEHİR OSMANGAZI UNIVERSITY – FACULTY OF EDUCATION
This work is licensed under a Creative Commons Attribution 4.0 International License. http://creativecommons.org/licenses/by-nc/4.0/
3. Role of JPAContainer in binding Vaadin
components to a database
Vaadin JPAContainer allows connecting Vaadin user interface components directly to the
persistent model objects.
You can use the container to display data in a table, tree, any other selection component, or
edit the data in a form.
5. Vaadin Data Model-Binding Components
to Data
The model allows binding user interface
components directly to the data that they display and
possibly allow to edit. There are three nested levels
of hierarchy in the data model: property, item,
and container. Using a spreadsheet application as an
analogy, these would correspond to a cell, a row, and
a table, respectively.
The Data Model is realized as a set of interfaces in
the com.vaadin.data package. The package contains
the Property, Item, and Container interfaces, along
with a number of more specialized interfaces and
classes.
6. Vaadin Data Model-Binding Components
to Data
The Data Model has many important and useful
features, such as support for change notification.
Especially containers have many helper interfaces,
including ones that allow indexing, ordering, sorting,
and filtering the data.
Field components provide a number of features
involving the data model, such as buffering,
validation, and lazy loading.
7. Properties
The Property interface is the base of the Vaadin Data Model. It provides a standardized API for
a single data value object that can be read (get) and written (set).
You can set the value of a property with setValue() and read with getValue()
8. Property Viewers and Editors
A property can be bound to a component
implementing the Viewer interface with
setPropertyDataSource()
You can use the same method in the Editor
interface to bind a component that allows
editing a particular property type to a
property.
12. Holding properties in Items
The Item interface provides access to a set of named properties.
Each property is identified by a property identifier (PID) and a reference to such a property can
be queried from an Item with getItemProperty() using the identifier.
13. Wrapping a Bean in a BeanItem
The BeanItem
implementation of the
Item interface is a wrapper
for Java Bean objects.
In fact, only the setters
and getters are required
while serialization and
other bean features are
not, so you can wrap
almost any POJOs with
minimal requirements.
14. Nested Beans
You may often have composite classes where one class "has a" another class.
15. Nested Beans
When shown in a Form, for example, you would
want to list the properties of the nested bean
along the properties of the composite bean.
You can do that by binding the properties of the
nested bean individually with a MethodProperty
or NestedMethodProperty.
The difference is that NestedMethodProperty
does not access the nested bean immediately but
only when accessing the property values, while
when using MethodProperty the nested bean is
accessed when creating the method property.
The difference is only significant if the nested
bean can be null or be changed later.
17. A Form with Nested Bean Properties
The item could be any item type, as described earlier.
18. A Form with Nested Bean Properties
Design a form for editing the data.
19. A Form with Nested Bean Properties
Bind the fields to the data as follows:
20. Collecting Items in Containers
All of the user interface components using containers also implement the relevant container
interfaces themselves, so that the access to the underlying data source is delegated through the
component.
25. Role of JPAContainer in binding Vaadin
components to a database
Vaadin JPAContainer allows connecting Vaadin user interface components directly to the
persistent model objects.
You can use the container to display data in a table, tree, any other selection component, or
edit the data in a form.
26. Properties
Atomic data is represented as Property objects that have a value and a type. Properties can be
bound to Field components, such as a TextField, or a table cell.
The ObjectProperty used above is just one implementation of the Property interface – in
JPAContainer we use a different property type.
27. Items
An Item is a collection of properties that is typically bound to a Form or a row in a Table or
some other selection component. Properties of an item are identified by a property identifier
(PID).
28. Containers
A Container is a collection of items, usually bound to a Table, Tree, or some other selection
component. Items in a container are identified by an item identifier (IID). Normally, all the items
in a container have the same type and the same properties.
29. Normal (Non-Persistent) Binding to
JavaBeans
Vaadin core library provides BeanItem implementation of the Item interface to bind bean objects. At the
Container level, Vaadin provides the BeanItemContainer and BeanContainer implementations.
They are very useful for handling transient (non-persistent) objects.
30. Java Persistence API
Java Persistence API (JPA) is an API for object-
relational mapping (ORM) of Java objects to a
relational database.
In JPA and entity-relationship modeling in general,
a Java class is considered an entity.
Class (or entity) instances correspond with a row in
a database table and member variables of a class
with columns.
Entities can also have relationships with other
entities.