SlideShare a Scribd company logo
1 of 89
Download to read offline
Binding business data to
Vaadin components
Best practices
Peter Lehto
Senior Vaadin Expert
@peter_lehto
Application
architecture
Data transfer
Vaadin
Containers
Vaadin
Fields
Application
Architecture
Deployment
<<UI module>>
CustomerView ProductView
<<UI module>>
CustomerView ProductView
<<Commons module>>
DTOService CustomerDTOCustomerDTO
<<UI module>>
CustomerView ProductView
<<Backend module>>
<<Commons module>>
DTOService CustomerDTO
EntityService
CustomerDTO
DTOServiceBean
Application layers
Client Browser
DevDayUI
Client Browser
DevDayUI
Client Browser
CustomerView ProductView
DevDayUI
DTOService
Client Browser
CustomerView ProductView
DevDayUI
Client Browser
CustomerView ProductView
DTOService
Converters EntityService
DevDayUI
Client Browser
CustomerView ProductView
PersistenceUnit
DTOService
Converters EntityService
DevDayUI
Client Browser
CustomerView ProductView
PersistenceUnit
DTOService
Converters EntityService
@Local
public interface EntityService {
void storeEntity(AbstractEntity entity);
<E extends AbstractEntity> List<E> getAll(Class<E> entityType);
}
@Local
public interface EntityService {
void storeEntity(AbstractEntity entity);
<E extends AbstractEntity> List<E> getAll(Class<E> entityType);
<E extends AbstractEntity> E getEntityById(long id, Class<E> entityType);
<E extends AbstractEntity> List<E> getPagedEntities(Class<E> entityType,
int startIndex, int items, Object[] sortPropertyIds, boolean[] sortStates);
}
@Local
public interface DTOService {
<DTO extends AbstractDTOWithIdentity> List<DTO> getAllDtos(Class<DTO> dtoType);
}
@Local
public interface DTOService {
<DTO extends AbstractDTOWithIdentity> List<DTO> getAllDtos(Class<DTO> dtoType);
<DTO extends AbstractDTOWithIdentity> List<DTO> getPagedDtos(Class<DTO> dtoType,
int startIndex, int items, Object[] sortPropertyIds, boolean[] sortStates);
<DTO extends AbstractDTOWithIdentity> long getCount(Class<DTO> dtoType);
}
@Local
public interface DTOService {
<DTO extends AbstractDTOWithIdentity> List<DTO> getAllDtos(Class<DTO> dtoType);
<DTO extends AbstractDTOWithIdentity> List<DTO> getPagedDtos(Class<DTO> dtoType,
int startIndex, int items, Object[] sortPropertyIds, boolean[] sortStates);
<DTO extends AbstractDTOWithIdentity> long getCount(Class<DTO> dtoType);
<DTO extends AbstractDTOWithIdentity> DTO getDtoById(long itemId, Class<DTO> dtoType);
<DTO extends AbstractDTOWithIdentity> void storeDto(DTO dto);
}
@Stateless
public class DTOServiceBean implements DTOService, EntityService {
@PersistenceContext(unitName = "devday")
private EntityManager entityManager;
…
}
Data transfer
DTO (DataTransferObject)
POJO built by DTOService
DTO (DataTransferObject)
POJO built by DTOService
Minimal ondemand data item
DTO (DataTransferObject)
POJO built by DTOService
Minimal ondemand data item
Free from Entity model changes
DTO (DataTransferObject)
POJO built by DTOService
Minimal ondemand data item
Free from Entity model changes
No referenced property loading
concerns
DTO (DataTransferObject)
Entity <-> DTO Conversion
UI needs DTOs
Entity <-> DTO Conversion
UI needs DTOs
Backend knows about entities
Entity <-> DTO Conversion
UI needs DTOs
Backend knows about entities
Converter per DTO / usecase type
Entity <-> DTO Conversion
public interface EntityToDTOConverter {
AbstractDTOWithIdentity convertToDTO(AbstractEntity entity);
Class<? extends AbstractEntity> getEntityType();
Class<? extends AbstractDTOWithIdentity> getDTOType();
}
public interface EntityToDTOConverter {
AbstractDTOWithIdentity convertToDTO(AbstractEntity entity);
Class<? extends AbstractEntity> getEntityType();
Class<? extends AbstractDTOWithIdentity> getDTOType();
}
public interface DTOToEntityConverter {
<DTO extends AbstractDTOWithIdentity, E extends AbstractEntity> E convertToEntity(DTO dto);
Class<? extends AbstractEntity> getEntityType();
Class<? extends AbstractDTOWithIdentity> getDTOType();
}
How to find converter?
Runtime
Instance
selection
@Retention(RUNTIME)
@Target(TYPE)
@Qualifier
public @Interface DTOType {
}
@Retention(RUNTIME)
@Target(TYPE)
@Qualifier
public @Interface DTOType {
Class<? extends AbstractDTO> value();
}
@DTOType(CustomerListingDTO.class)
public class CustomerEntityToListingDTOConverter implements EntityToDTOConverter {
@Override
public Class<CustomerEntity> getEntityType() {
return CustomerEntity.class;
}
@Override
public Class<CustomerListingDTO> getDTOType() {
return CustomerListingDTO.class;
}
@Override
public CustomerListingDTO convertToDTO(CustomerEntity e) {
…
}
}
public class DTOTypeAnnotationLiteral extends AnnotationLiteral<DTOType> implements DTOType {
private Class<? extends AbstractDTO> dtoType;
public DTOTypeAnnotationLiteral(Class<? extends AbstractDTO> dtoType) {
this.dtoType = dtoType;
}
@Override
public Class<? extends AbstractDTO> value() {
return dtoType;
}
}
protected EntityToDTOConverter findEntityToDTOConverter(
Class<? extends AbstractDTO> dtoType) {
Instance<EntityToDTOConverter> converterSelection = converterInstantiator
.select(new DTOTypeAnnotationLiteral(dtoType));
if (converterSelection.isAmbiguous()) {
// more than one converter for same type exception…
}
if (converterSelection.isUnsatisfied()) {
// no converter available exception
}
return converterSelection.get();
}
DTOService + Converter
No need to change code
DTOService + Converter
No need to change code
Add new converters for new DTO types
DTOService + Converter
No need to change code
Add new converters for new DTO types
Converters via bean discovery
DTOService + Converter
No need to change code
Add new converters for new DTO types
Converters via bean discovery
UI knows and works only with DTOs
DTOService + Converter
Reading data through
Vaadin
Containers
Data binding
Container
Item
Property
In memory containers
In memory containers
IndexedContainer – Basic container
that is manually built
In memory containers
HierarchicalContainer – IndexedContainer
that supports parent/child relationships
IndexedContainer – Basic container
that is manually built
In memory containers
BeanItemContainer – A container that is
automatically built from a collection of
Java Beans
HierarchicalContainer – IndexedContainer
that supports parent/child relationships
IndexedContainer – Basic container
that is manually built
100
Browser
Container
100
Server side UI Browser
DB Container
1 000 000 100
Backend Server side UI Browser
DB Container
1 000 000 100
Backend Server side UI Browser
Handled by the table
component
Reduce memory footprint with
Lazy loading
LazyQueryContainer
Add-on from Vaadin Directory
LazyQueryContainer
Add-on from Vaadin Directory
Retrieve data by index
LazyQueryContainer
Add-on from Vaadin Directory
Retrieve data by index
Will not expose backend assets
LazyQueryContainer
Grid grid = new Grid();
container = new LazyQueryContainer(queryFactory, PRIMARY_KEY_PROPERTY, BATCH_SIZE);
grid.setContainerDataSource(container);
public class LazyDTOQuery<DTO extends AbstractDTO> extends AbstractBeanQuery<DTO> {
private Class<DTO> dtoType;
private DTOService dtoService;
public LazyDTOQuery(Class<DTO> dtoType, DTOService dtoService,
QueryDefinition queryDefinition) {
super(…);
}
@Override
protected List<DTO> loadBeans(int startIndex, int numItems) {
return dtoService.getPagedDtos(dtoType, startIndex, numItems,
getSortPropertyIds(), getSortStates());
}
@Override
public int size() {
return dtoService.getCount(dtoType);
}
…
}
Binding data with
Vaadin Fields
Examples of Fields
Vaadin Fields
Fields are Components with databinding
Vaadin Fields
Fields are Components with databinding
Fields can be bound to properties
Vaadin Fields
Fields are Components with databinding
Fields can be bound to properties
Group of properties is an Item
Vaadin Fields
public class Person {
private String name;
private int age;
// Getters and setters omitted
}
public class Person {
private String name;
private int age;
// Getters and setters omitted
}
BeanItem<Person> item =
new BeanItem<Person>(person);
public class Person {
private String name;
private int age;
// Getters and setters omitted
}
BeanItem<Person> item =
new BeanItem<Person>(person);
Property ID Type Value
“name” String.class “John Doe”
“age” Integer.class 42
public class Person {
private String name;
private int age;
// Getters and setters omitted
}
BeanItem<Person> item =
new BeanItem<Person>(person);
Property ID Type Value
“name” String.class “John Doe”
“age” Integer.class 42
Separate Field value from
Property value with
Buffering
Buffering
setPropertyDatasource(property);
Buffering
setPropertyDatasource(property);
setBuffered(true);
Buffering
setPropertyDatasource(property);
setBuffered(true);
commit();
Buffering
setPropertyDatasource(property);
setBuffered(true);
commit();
discard();
Buffering
Buffering
Data source
UI Logic
AbstractField
Button
Browser
Buffering
Data source
UI Logic
AbstractField
Button
Browser
TextField
value
change
Buffering
Data source
UI Logic
AbstractField
Button
Browser
TextField
value
change
Save button
pressed
Buffering
Data source
UI Logic
AbstractField
Button
Browser
TextField
value
change
Save button
pressed
ClickEvent
commit()
Buffering
Data source
UI Logic
AbstractField
Button
Browser
TextField
value
change
Save button
pressed
ClickEvent
commit()
Buffering
Data source
UI Logic
AbstractField
Button
Browser
TextField
value
change
Save button
pressed
ClickEvent
FieldGroup
combining many Fields
together
(used to be Form)
setItemDataSource(Item item)
?
What is the difference between
these two method calls?
comboBox.
setPropertyDataSource(property);
comboBox.
setContainerDataSource(container);

More Related Content

What's hot

Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
Dmitry Buzdin
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
Anh Quân
 

What's hot (20)

Vaadin 7 - Java Enterprise Edition integration
Vaadin 7 - Java Enterprise Edition integrationVaadin 7 - Java Enterprise Edition integration
Vaadin 7 - Java Enterprise Edition integration
 
Vaadin Flow - JavaLand 2018
Vaadin Flow - JavaLand 2018Vaadin Flow - JavaLand 2018
Vaadin Flow - JavaLand 2018
 
GWT integration with Vaadin
GWT integration with VaadinGWT integration with Vaadin
GWT integration with Vaadin
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google Guice
 
Vaadin DevDay 2017 - Web Components
Vaadin DevDay 2017 - Web ComponentsVaadin DevDay 2017 - Web Components
Vaadin DevDay 2017 - Web Components
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
 
Google Guice
Google GuiceGoogle Guice
Google Guice
 
MongoDB Stitch Tutorial
MongoDB Stitch TutorialMongoDB Stitch Tutorial
MongoDB Stitch Tutorial
 
Building web apps with Vaadin 8
Building web apps with Vaadin 8 Building web apps with Vaadin 8
Building web apps with Vaadin 8
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
What's new in Vaadin 8, how do you upgrade, and what's next?
What's new in Vaadin 8, how do you upgrade, and what's next?What's new in Vaadin 8, how do you upgrade, and what's next?
What's new in Vaadin 8, how do you upgrade, and what's next?
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java Developers
 
Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular U
 
Inversion of Control and Dependency Injection
Inversion of Control and Dependency InjectionInversion of Control and Dependency Injection
Inversion of Control and Dependency Injection
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Speed up your GWT coding with gQuery
Speed up your GWT coding with gQuerySpeed up your GWT coding with gQuery
Speed up your GWT coding with gQuery
 
Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]Rapid development tools for java ee 8 [tut2998]
Rapid development tools for java ee 8 [tut2998]
 

Similar to Binding business data to vaadin components

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
Droidcon Berlin
 

Similar to Binding business data to vaadin components (20)

Building Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture ComponentsBuilding Modern Apps using Android Architecture Components
Building Modern Apps using Android Architecture Components
 
Vertx SouJava
Vertx SouJavaVertx SouJava
Vertx SouJava
 
Vertx daitan
Vertx daitanVertx daitan
Vertx daitan
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Devoxx 2012 (v2)
Devoxx 2012 (v2)Devoxx 2012 (v2)
Devoxx 2012 (v2)
 
Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
Enforce Consistency through Application Infrastructure
Enforce Consistency through Application InfrastructureEnforce Consistency through Application Infrastructure
Enforce Consistency through Application Infrastructure
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
 
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
 
Building Reactive Microservices with Vert.x
Building Reactive Microservices with Vert.xBuilding Reactive Microservices with Vert.x
Building Reactive Microservices with Vert.x
 

Recently uploaded

Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 

Recently uploaded (18)

Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptx
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 

Binding business data to vaadin components