+ All Categories
Home > Education > Vaadin JPAContainer

Vaadin JPAContainer

Date post: 17-Jul-2015
Category:
Upload: cmkandemir
View: 125 times
Download: 6 times
Share this document with a friend
Popular Tags:
32
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/
Transcript

Vaadin Data Model and

JPAContainerYRD.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/

Three-Layer ArchitectureThe data binding model in Vaadin can be used to bind user interface components to a domain layer.

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.

Data Model

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.

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.

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()

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.

Field Validation

ObjectProperty Implementation�The ObjectProperty class is a simple implementation of the Property interface that allows storing an arbitrary Java object.

Converting Between Property Type and Representation

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.

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.

Nested BeansYou may often have composite classes where one class "has a" another class.

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.

A Form with Nested Bean Properties

A Form with Nested Bean PropertiesThe item could be any item type, as described earlier.

A Form with Nested Bean PropertiesDesign a form for editing the data.

A Form with Nested Bean PropertiesBind the fields to the data as follows:

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.

Creating and Binding a Container

More details about Data Model

https://vaadin.com/book/-/page/datamodel.html

Vaadin JPAContainer

Three-Layer ArchitectureThe data binding model in Vaadin can be used to bind user interface components to a domain layer.

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.

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.

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).

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.

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.

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.

Installing Vaadin JPAContainer�https://vaadin.com/book/-/page/jpacontainer.installation.html

�https://vaadin.com/directory#!addon/vaadin-jpacontainer

JPAContainer AddressBook DemoNext Lab�https://vaadin.com/tutorial


Recommended