SlideShare uma empresa Scribd logo
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);

Mais conteúdo relacionado

Mais procurados

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

Mais procurados (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]
 

Semelhante a Binding business data to vaadin components

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
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
 

Semelhante a 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
 
Building Reactive Microservices with Vert.x
Building Reactive Microservices with Vert.xBuilding Reactive Microservices with Vert.x
Building Reactive Microservices with Vert.x
 
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 ...
 

Último

527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf
rajpreetkaur75080
 
Cymulate (Breach and Attack Simulation).
Cymulate (Breach and Attack Simulation).Cymulate (Breach and Attack Simulation).
Cymulate (Breach and Attack Simulation).
luckyk1575
 

Último (15)

Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
Writing Sample 2 -Bridging the Divide: Enhancing Public Engagement in Urban D...
 
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdfOracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
Oracle Database Administration I (1Z0-082) Exam Dumps 2024.pdf
 
Hi-Tech Industry 2024-25 Prospective.pptx
Hi-Tech Industry 2024-25 Prospective.pptxHi-Tech Industry 2024-25 Prospective.pptx
Hi-Tech Industry 2024-25 Prospective.pptx
 
Breathing in New Life_ Part 3 05 22 2024.pptx
Breathing in New Life_ Part 3 05 22 2024.pptxBreathing in New Life_ Part 3 05 22 2024.pptx
Breathing in New Life_ Part 3 05 22 2024.pptx
 
527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf527598851-ppc-due-to-various-govt-policies.pdf
527598851-ppc-due-to-various-govt-policies.pdf
 
Understanding Poverty: A Community Questionnaire
Understanding Poverty: A Community QuestionnaireUnderstanding Poverty: A Community Questionnaire
Understanding Poverty: A Community Questionnaire
 
05232024 Joint Meeting - Community Networking
05232024 Joint Meeting - Community Networking05232024 Joint Meeting - Community Networking
05232024 Joint Meeting - Community Networking
 
OC Streetcar Final Presentation-Downtown Santa Ana
OC Streetcar Final Presentation-Downtown Santa AnaOC Streetcar Final Presentation-Downtown Santa Ana
OC Streetcar Final Presentation-Downtown Santa Ana
 
Deciding The Topic of our Magazine.pptx.
Deciding The Topic of our Magazine.pptx.Deciding The Topic of our Magazine.pptx.
Deciding The Topic of our Magazine.pptx.
 
123445566544333222333444dxcvbcvcvharsh.pptx
123445566544333222333444dxcvbcvcvharsh.pptx123445566544333222333444dxcvbcvcvharsh.pptx
123445566544333222333444dxcvbcvcvharsh.pptx
 
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
 
The Canoga Gardens Development Project. PDF
The Canoga Gardens Development Project. PDFThe Canoga Gardens Development Project. PDF
The Canoga Gardens Development Project. PDF
 
The Influence and Evolution of Mogul Press in Contemporary Public Relations.docx
The Influence and Evolution of Mogul Press in Contemporary Public Relations.docxThe Influence and Evolution of Mogul Press in Contemporary Public Relations.docx
The Influence and Evolution of Mogul Press in Contemporary Public Relations.docx
 
Cymulate (Breach and Attack Simulation).
Cymulate (Breach and Attack Simulation).Cymulate (Breach and Attack Simulation).
Cymulate (Breach and Attack Simulation).
 
ServiceNow CIS-Discovery Exam Dumps 2024
ServiceNow CIS-Discovery Exam Dumps 2024ServiceNow CIS-Discovery Exam Dumps 2024
ServiceNow CIS-Discovery Exam Dumps 2024
 

Binding business data to vaadin components