SlideShare ist ein Scribd-Unternehmen logo
1 von 77
Downloaden Sie, um offline zu lesen
VA A D I N W I T H S P R I N G
THINK WITH BEANS!
@peter_lehto
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views as Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views as Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
W h a t D e p e n d e n c y I n j e c t i o n ?
Dependency Injection (DI) is a runtime mechanism
Dependency Injection (DI) is a runtime mechanism
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily manage
the lifecycle of the dependent object.
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily
manage the lifecycle of the dependent object.
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily
manage the lifecycle of the dependent object.
Instead with DI a special DI container takes care of the
object lifecycle management
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily
manage the lifecycle of the dependent object.
Instead with DI a special DI container takes care of
the object lifecycle management
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily
manage the lifecycle of the dependent object.
Instead with DI a special DI container takes care of
the object lifecycle management where clients
reference managed and possibly shared objects.
Dependency Injection (DI) is a runtime mechanism
where dependency between the client object and the
dependent object does not occur directly.
With DI the client object does not necessarily
manage the lifecycle of the dependent object.
Instead with DI a special DI container takes care of
the object lifecycle management where clients
reference managed and possibly shared objects.
T L ; D R
public interface MainMenu { … }
T L ; D R
public interface MainMenu { … }
public class DefaultMainMenu implements MainMenu { … }
T L ; D R
public interface MainMenu { … }
public class DefaultMainMenu implements MainMenu { … }
public class ResponsiveMainMenu implements MainMenu { … }
T L ; D R
public interface MainMenu { … }
public class DefaultMainMenu implements MainMenu { … }
public class ResponsiveMainMenu implements MainMenu { … }
@Autowired
private MainMenu mainMenu;
W h y ?
•
Loose coupling
•
Dependency inversion
•
High Abstraction
•
Highly cohesive modules
•
Deployment time config
H o w ?
@SpringComponent
public class DefaultMainMenu implements MainMenu { … }
D e f i n e B e a n
@SpringComponent
@UIScope
public class DefaultMainMenu implements MainMenu { … }
D e f i n e B e a n
@Configuration
public class ComponentConfiguration {
@Bean
@Primary
public MainMenu provideDefaultMenu {
return new DefaultMainMenu();
}
D e f i n e B e a n
@Bean
@Responsive
public MainMenu provideResponsiveMenu {
return new ResponsiveMainMenu();
}
}
W i t h @ A u t o w i r e d a n d
MANAGED BEANS
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views a Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
Automatic discovery
and lookup
UI AS BEAN
@SpringUI
public class DevDayTestUI extends UI {
path attribute for
URL binding
UI AS BEAN
@SpringUI(path = "app")
public class DevDayTestUI extends UI {
@SpringUI
public class DevDayTestUI extends UI {
localhost:8080/context
UI AS BEAN
localhost:8080/context/app
@SpringUI(path = "app")
public class DevDayTestUI extends UI {
@SpringUI
public class DevDayTestUI extends UI {
HorizontalLayoutContentAreaMenu
View1
View2
View3
HorizontalLayoutView1Menu
View1
View2
View3
HorizontalLayoutView2Menu
View1
View2
View3
HorizontalLayoutView3Menu
View1
View2
View3
Implement View and
annotate with
@SpringView
VIEW AS BEAN
@SpringView(name = "customers")
public class CustomerView extends VerticalLayout
implements View {
Wrapper for View
Component in UI
VIEWDISPLAY
@SpringViewDisplay
public class DevDayViewDisplay
extends VerticalSplitPanel
implements ViewDisplay {
S p r i n g B o o t
AUTO CONFIGURATION
S e t s e v e r y t h i n g u p
H o w a r e t h e b e a n
i n s t a n c e s m a n a g e d ?
WITH SCOPES
@ S e s s i o n S c o p e
WITH SCOPES
@Autowired
private User currentUser;
@ S e s s i o n S c o p e
@ S e s s i o n S c o p e
@ U I S c o p e
WITH SCOPES
public interface MainMenu { … }
@Autowired
private MainMenu mainMenu;
@SpringComponent
@UIScope
public class DefaultMainMenu implements MainMenu { … }
@ U I S c o p e
@ S e s s i o n S c o p e
@ U I S c o p e
@ V i e w S c o p e
WITH SCOPES
@SpringComponent
@ViewScope
public class DataTable {
@Autowired
private EventBus.ViewEventBus eventBus;
@ V i e w S c o p e
@ S e s s i o n S c o p e
@ U I S c o p e
@ V i e w S c o p e
@ R e q u e s t S c o p e
WITH SCOPES
public interface HttpRequestStopWatch { … }
@ R e q u e s t S c o p e
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views a Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
S p r i n g V i e w P r o v i d e r
SPRING NAVIGATOR
@Autowired
private Navigator navigator;
navigator.navigateTo(“customers”);
N a v i g a t o r
V i e w b e a n d i s c o v e r y b y @ S p r i n g V i e w
SPRING NAVIGATOR
public interface ViewAccessControl;
public interface ViewInstanceAccessControl;
C o n t r o l l i n g a c c e s s t o v i e w s
public interface ViewAccessControl;
public interface ViewInstanceAccessControl;
C o n t r o l l i n g a c c e s s t o v i e w s
WITHOUT
SPRING SECURITY
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views a Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
E n a b l i n g S p r i n g S e c u r i t y
w i t h S p r i n g B o o t
@EnableVaadinManagedSecurity
Va a d i n M a n a g e d S e c u r i t y
• Vaadin will manage Spring’s SecurityContext
• Disable auto configuration for SpringSecurity
• Vaadin app is the only web app secured
• Signing in and out takes place through Vaadin UI
• @PreAuthorize and @Secured
E n a b l i n g S p r i n g S e c u r i t y
w i t h S p r i n g B o o t
@EnableVaadinSharedSecurity
Va a d i n S h a r e d S e c u r i t y
• Vaadin behaves as regular web app secured by Spring
• Signing in and out may take place outside Vaadin
• Manual Spring Security configuration needed
• Web Socket based @Push not available due to HTTP Filters
• @PreAuthorize and @Secured
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views a Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
E v e n t B u s
@SpringComponent
@ViewScope
public class DataEditor<DTO> {
}
E v e n t B u s
@SpringComponent
@ViewScope
public class DataEditor<DTO> {
@Autowired
private EventBus.ViewEventBus eventBus;
…
}
E v e n t B u s
@SpringComponent
@ViewScope
public class DataEditor<DTO> {
@Autowired
private EventBus.ViewEventBus eventBus;
protected void onSaveClicked() {
eventBus.publish(this, new EditorSaveEvent());
}
…
}
@SpringComponent
@ViewScope
public class DataTable<DTO> extends Grid<DTO> {
@Autowired
private EventBus.ViewEventBus eventBus;
}
@SpringComponent
@ViewScope
public class DataTable<DTO> extends Grid<DTO> {
@Autowired
private EventBus.ViewEventBus eventBus;
@PostConstruct
protected void initialize() {
eventBus.subscribe(this);
}
}
@SpringComponent
@ViewScope
public class DataTable<DTO> extends Grid<DTO> {
@Autowired
private EventBus.ViewEventBus eventBus;
@PostConstruct
protected void initialize() {
eventBus.subscribe(this);
}
@EventBusListenerMethod
protected void onSaveEvent(EditorSaveEvent e) {
getDataProvider().refreshAll();
}
}
Session’s content
• Dependency Injection (DI) Briefly
• Setting up UI, ViewDisplay and Views a Beans
• Navigation, ViewAccessControl
• Securing with Spring Security
• EventBus and other DI Extensions
• Tips and Tricks for Springifying your Vaadin app
S e t t i n g u p m e n u a u t o m a t i c a l l y
@MenuDefinition(icon=, name=, order=)
@SpringView(name=“customers”)
public class CustomerViewBean implements View… {
…
}
S e t t i n g u p m e n u a u t o m a t i c a l l y
private void findAndPopulateMenuItems() {
List<String> beanNames = Arrays.asList(context.
getBeanNamesForAnnotation(MenuDefinition.class));
}
S e t t i n g u p m e n u a u t o m a t i c a l l y
private void findAndPopulateMenuItems() {
List<String> beanNames = Arrays.asList(context.
getBeanNamesForAnnotation(MenuDefinition.class));
Map<String, MenuDefinition> definitionsToNames = beanNames.stream().
collect(Collectors.toMap(Function.identity(),
beanName -> context.findAnnotationOnBean(beanName, MenuDefinition.class)));
Map<String, SpringView> viewsToNames = beanNames.stream().
collect(Collectors.toMap(Function.identity(),
beanName -> context.findAnnotationOnBean(beanName, SpringView.class)));
}
S e t t i n g u p m e n u a u t o m a t i c a l l y
private void findAndPopulateMenuItems() {
List<String> beanNames = Arrays.asList(context.
getBeanNamesForAnnotation(MenuDefinition.class));
Map<String, MenuDefinition> definitionsToNames = beanNames.stream().
collect(Collectors.toMap(Function.identity(),
beanName -> context.findAnnotationOnBean(beanName, MenuDefinition.class)));
Map<String, SpringView> viewsToNames = beanNames.stream().
collect(Collectors.toMap(Function.identity(),
beanName -> context.findAnnotationOnBean(beanName, SpringView.class)));
beanNames.forEach(beanName -> {
MenuDefinition menuDefinition = definitionsToNames.get(beanName);
SpringView viewDefinition = viewsToNames.get(beanName);
addMenuItem(menuDefinition.name(), menuDefinition.icon(),
viewDefinition.name());
});
Va a d i n I 1 8 N S u p p o r t
@EnableI18N
Va a d i n I 1 8 N S u p p o r t
@EnableI18N
@Bean
I18N i18n() {
return new I18N(context);
}
Va a d i n I 1 8 N S u p p o r t
@EnableI18N
@Bean
I18N i18n() {
return new I18N(context);
}
@Bean
CompositeMessageSource messageSource() {
return new CompositeMessageSource(context);
}
Va a d i n I 1 8 N S u p p o r t
@Bean
MessageProvider provideTranslations() {
return new ResourceBundleMessageProvider
(“com.foo.path.to.bundle”, "UTF-8");
}
P r o g r a m m a t i c B e a n L o o k u p
@Component
public class GenericBeanResolver { … }
Lessons learned
• DI is a powerful mechanism to decouple code
• Following DI almost certainly guarantees that best practices
are followed
• Vaadin supports DI with Spring and CDI, both through their
own integration addons
• Lot of Spring functionality is based on Beans
• Structuring Vaadin app with Bean approach can provide
great flexibility and robustness
T H A N K Y O U !
PLEASE RATE THE TALK
@
FLIP CHART BY THE DOOR!
@peter_lehto

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Vaadin DevDay 2017 - Web Components
Vaadin DevDay 2017 - Web ComponentsVaadin DevDay 2017 - Web Components
Vaadin DevDay 2017 - Web Components
 
Vaadin with Java EE 7
Vaadin with Java EE 7Vaadin with Java EE 7
Vaadin with Java EE 7
 
Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8Vaadin DevDay 2017 - Data Binding in Vaadin 8
Vaadin DevDay 2017 - Data Binding in Vaadin 8
 
GWT integration with Vaadin
GWT integration with VaadinGWT integration with Vaadin
GWT integration with Vaadin
 
Vaadin 7 - Java Enterprise Edition integration
Vaadin 7 - Java Enterprise Edition integrationVaadin 7 - Java Enterprise Edition integration
Vaadin 7 - Java Enterprise Edition integration
 
Introduction to Vaadin
Introduction to VaadinIntroduction to Vaadin
Introduction to Vaadin
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
Android data binding
Android data bindingAndroid data binding
Android data binding
 
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
 
MVVM & Data Binding Library
MVVM & Data Binding Library MVVM & Data Binding Library
MVVM & Data Binding Library
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
Vaadin Components
Vaadin ComponentsVaadin Components
Vaadin Components
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data Binding
 
Data Binding in Action using MVVM pattern
Data Binding in Action using MVVM patternData Binding in Action using MVVM pattern
Data Binding in Action using MVVM pattern
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | Edureka
 
Wicket Next (1.4/1.5)
Wicket Next (1.4/1.5)Wicket Next (1.4/1.5)
Wicket Next (1.4/1.5)
 
Data binding w Androidzie
Data binding w AndroidzieData binding w Androidzie
Data binding w Androidzie
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
Vaadin & Web Components
Vaadin & Web ComponentsVaadin & Web Components
Vaadin & Web Components
 

Andere mochten auch

Capítol 1 música amagada
Capítol 1 música amagadaCapítol 1 música amagada
Capítol 1 música amagada
Joanprofe
 

Andere mochten auch (14)

Vaadin 8 - Data Binding with Binder
Vaadin 8 - Data Binding with BinderVaadin 8 - Data Binding with Binder
Vaadin 8 - Data Binding with Binder
 
Remote controlling Parrot AR Drone with Spring Boot & Vaadin (JavaCro15)
Remote controlling Parrot AR Drone with Spring Boot & Vaadin (JavaCro15)Remote controlling Parrot AR Drone with Spring Boot & Vaadin (JavaCro15)
Remote controlling Parrot AR Drone with Spring Boot & Vaadin (JavaCro15)
 
Remote controlling Parrot AR drone with Vaadin & Spring Boot @ GWT.create
Remote controlling Parrot AR drone with Vaadin & Spring Boot @ GWT.createRemote controlling Parrot AR drone with Vaadin & Spring Boot @ GWT.create
Remote controlling Parrot AR drone with Vaadin & Spring Boot @ GWT.create
 
WebApp controlled Parrot AR Drone with Vaadin and Spring Boot
WebApp controlled Parrot AR Drone with Vaadin and Spring BootWebApp controlled Parrot AR Drone with Vaadin and Spring Boot
WebApp controlled Parrot AR Drone with Vaadin and Spring Boot
 
Building web apps with vaadin 8
Building web apps with vaadin 8Building web apps with vaadin 8
Building web apps with vaadin 8
 
정품수면제구입 ̄http://7cc.kr"「톡:c2017」정품수면제 구입처г수면제 구입방법ㄅ수면제 판매,수면제 구입,수면제 파는곳,수면제 처...
정품수면제구입 ̄http://7cc.kr"「톡:c2017」정품수면제 구입처г수면제 구입방법ㄅ수면제 판매,수면제 구입,수면제 파는곳,수면제 처...정품수면제구입 ̄http://7cc.kr"「톡:c2017」정품수면제 구입처г수면제 구입방법ㄅ수면제 판매,수면제 구입,수면제 파는곳,수면제 처...
정품수면제구입 ̄http://7cc.kr"「톡:c2017」정품수면제 구입처г수면제 구입방법ㄅ수면제 판매,수면제 구입,수면제 파는곳,수면제 처...
 
Logo quiz
Logo quizLogo quiz
Logo quiz
 
conférénce client
conférénce clientconférénce client
conférénce client
 
Capítol 1 música amagada
Capítol 1 música amagadaCapítol 1 música amagada
Capítol 1 música amagada
 
Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.
 
「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しました「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しました
 
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
 
Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017
 
Presentacion estrella rural
Presentacion estrella ruralPresentacion estrella rural
Presentacion estrella rural
 

Ähnlich wie Vaadin 8 with Spring Framework

Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight Applications
Dan Wahlin
 
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
DataLeader.io
 
Pioneer a Strategic Change in Content Organization with Plone
Pioneer a Strategic Change in Content Organization with PlonePioneer a Strategic Change in Content Organization with Plone
Pioneer a Strategic Change in Content Organization with Plone
Clayton Parker
 
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In TechnologyUniversal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Badoo
 

Ähnlich wie Vaadin 8 with Spring Framework (20)

JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
 
A tour through Swift attributes
A tour through Swift attributesA tour through Swift attributes
A tour through Swift attributes
 
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
 
Android accessibility for developers and QA
Android accessibility for developers and QAAndroid accessibility for developers and QA
Android accessibility for developers and QA
 
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight Applications
 
Riacon swiz
Riacon swizRiacon swiz
Riacon swiz
 
Agile Australia 2014: Workshop - Design and Implementation of Microservices
Agile Australia 2014: Workshop - Design and Implementation of MicroservicesAgile Australia 2014: Workshop - Design and Implementation of Microservices
Agile Australia 2014: Workshop - Design and Implementation of Microservices
 
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
 
Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.
 
Pioneer a Strategic Change in Content Organization with Plone
Pioneer a Strategic Change in Content Organization with PlonePioneer a Strategic Change in Content Organization with Plone
Pioneer a Strategic Change in Content Organization with Plone
 
Swiz DAO
Swiz DAOSwiz DAO
Swiz DAO
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring security jwt tutorial toptal
Spring security jwt tutorial   toptalSpring security jwt tutorial   toptal
Spring security jwt tutorial toptal
 
"Universal programming recipes", Kateryna Trofimenko
"Universal programming recipes", Kateryna Trofimenko"Universal programming recipes", Kateryna Trofimenko
"Universal programming recipes", Kateryna Trofimenko
 
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In TechnologyUniversal programming recipes​ - Ekaterina Trofimenko - Women In Technology
Universal programming recipes​ - Ekaterina Trofimenko - Women In Technology
 
From mvc to viper
From mvc to viperFrom mvc to viper
From mvc to viper
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Web 2.0 security woes
Web 2.0 security woesWeb 2.0 security woes
Web 2.0 security woes
 
Spring Boot Whirlwind Tour
Spring Boot Whirlwind TourSpring Boot Whirlwind Tour
Spring Boot Whirlwind Tour
 

Kürzlich hochgeladen

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Kürzlich hochgeladen (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

Vaadin 8 with Spring Framework

  • 1. VA A D I N W I T H S P R I N G THINK WITH BEANS! @peter_lehto
  • 2. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views as Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 3. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views as Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 4. W h a t D e p e n d e n c y I n j e c t i o n ?
  • 5. Dependency Injection (DI) is a runtime mechanism
  • 6. Dependency Injection (DI) is a runtime mechanism
  • 7. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly.
  • 8. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly.
  • 9. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object.
  • 10. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object.
  • 11. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object. Instead with DI a special DI container takes care of the object lifecycle management
  • 12. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object. Instead with DI a special DI container takes care of the object lifecycle management
  • 13. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object. Instead with DI a special DI container takes care of the object lifecycle management where clients reference managed and possibly shared objects.
  • 14. Dependency Injection (DI) is a runtime mechanism where dependency between the client object and the dependent object does not occur directly. With DI the client object does not necessarily manage the lifecycle of the dependent object. Instead with DI a special DI container takes care of the object lifecycle management where clients reference managed and possibly shared objects.
  • 15. T L ; D R public interface MainMenu { … }
  • 16. T L ; D R public interface MainMenu { … } public class DefaultMainMenu implements MainMenu { … }
  • 17. T L ; D R public interface MainMenu { … } public class DefaultMainMenu implements MainMenu { … } public class ResponsiveMainMenu implements MainMenu { … }
  • 18. T L ; D R public interface MainMenu { … } public class DefaultMainMenu implements MainMenu { … } public class ResponsiveMainMenu implements MainMenu { … } @Autowired private MainMenu mainMenu;
  • 19. W h y ?
  • 20. • Loose coupling • Dependency inversion • High Abstraction • Highly cohesive modules • Deployment time config
  • 21. H o w ?
  • 22. @SpringComponent public class DefaultMainMenu implements MainMenu { … } D e f i n e B e a n
  • 23. @SpringComponent @UIScope public class DefaultMainMenu implements MainMenu { … } D e f i n e B e a n
  • 24. @Configuration public class ComponentConfiguration { @Bean @Primary public MainMenu provideDefaultMenu { return new DefaultMainMenu(); } D e f i n e B e a n
  • 25. @Bean @Responsive public MainMenu provideResponsiveMenu { return new ResponsiveMainMenu(); } }
  • 26. W i t h @ A u t o w i r e d a n d MANAGED BEANS
  • 27. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views a Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 28. Automatic discovery and lookup UI AS BEAN @SpringUI public class DevDayTestUI extends UI {
  • 29. path attribute for URL binding UI AS BEAN @SpringUI(path = "app") public class DevDayTestUI extends UI { @SpringUI public class DevDayTestUI extends UI {
  • 30. localhost:8080/context UI AS BEAN localhost:8080/context/app @SpringUI(path = "app") public class DevDayTestUI extends UI { @SpringUI public class DevDayTestUI extends UI {
  • 35. Implement View and annotate with @SpringView VIEW AS BEAN @SpringView(name = "customers") public class CustomerView extends VerticalLayout implements View {
  • 36. Wrapper for View Component in UI VIEWDISPLAY @SpringViewDisplay public class DevDayViewDisplay extends VerticalSplitPanel implements ViewDisplay {
  • 37. S p r i n g B o o t AUTO CONFIGURATION S e t s e v e r y t h i n g u p
  • 38. H o w a r e t h e b e a n i n s t a n c e s m a n a g e d ?
  • 40. @ S e s s i o n S c o p e WITH SCOPES
  • 41. @Autowired private User currentUser; @ S e s s i o n S c o p e
  • 42. @ S e s s i o n S c o p e @ U I S c o p e WITH SCOPES
  • 43. public interface MainMenu { … } @Autowired private MainMenu mainMenu; @SpringComponent @UIScope public class DefaultMainMenu implements MainMenu { … } @ U I S c o p e
  • 44. @ S e s s i o n S c o p e @ U I S c o p e @ V i e w S c o p e WITH SCOPES
  • 45. @SpringComponent @ViewScope public class DataTable { @Autowired private EventBus.ViewEventBus eventBus; @ V i e w S c o p e
  • 46. @ S e s s i o n S c o p e @ U I S c o p e @ V i e w S c o p e @ R e q u e s t S c o p e WITH SCOPES
  • 47. public interface HttpRequestStopWatch { … } @ R e q u e s t S c o p e
  • 48. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views a Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 49. S p r i n g V i e w P r o v i d e r SPRING NAVIGATOR
  • 51. V i e w b e a n d i s c o v e r y b y @ S p r i n g V i e w SPRING NAVIGATOR
  • 52. public interface ViewAccessControl; public interface ViewInstanceAccessControl; C o n t r o l l i n g a c c e s s t o v i e w s
  • 53. public interface ViewAccessControl; public interface ViewInstanceAccessControl; C o n t r o l l i n g a c c e s s t o v i e w s WITHOUT SPRING SECURITY
  • 54. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views a Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 55. E n a b l i n g S p r i n g S e c u r i t y w i t h S p r i n g B o o t @EnableVaadinManagedSecurity
  • 56. Va a d i n M a n a g e d S e c u r i t y • Vaadin will manage Spring’s SecurityContext • Disable auto configuration for SpringSecurity • Vaadin app is the only web app secured • Signing in and out takes place through Vaadin UI • @PreAuthorize and @Secured
  • 57. E n a b l i n g S p r i n g S e c u r i t y w i t h S p r i n g B o o t @EnableVaadinSharedSecurity
  • 58. Va a d i n S h a r e d S e c u r i t y • Vaadin behaves as regular web app secured by Spring • Signing in and out may take place outside Vaadin • Manual Spring Security configuration needed • Web Socket based @Push not available due to HTTP Filters • @PreAuthorize and @Secured
  • 59. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views a Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 60. E v e n t B u s @SpringComponent @ViewScope public class DataEditor<DTO> { }
  • 61. E v e n t B u s @SpringComponent @ViewScope public class DataEditor<DTO> { @Autowired private EventBus.ViewEventBus eventBus; … }
  • 62. E v e n t B u s @SpringComponent @ViewScope public class DataEditor<DTO> { @Autowired private EventBus.ViewEventBus eventBus; protected void onSaveClicked() { eventBus.publish(this, new EditorSaveEvent()); } … }
  • 63. @SpringComponent @ViewScope public class DataTable<DTO> extends Grid<DTO> { @Autowired private EventBus.ViewEventBus eventBus; }
  • 64. @SpringComponent @ViewScope public class DataTable<DTO> extends Grid<DTO> { @Autowired private EventBus.ViewEventBus eventBus; @PostConstruct protected void initialize() { eventBus.subscribe(this); } }
  • 65. @SpringComponent @ViewScope public class DataTable<DTO> extends Grid<DTO> { @Autowired private EventBus.ViewEventBus eventBus; @PostConstruct protected void initialize() { eventBus.subscribe(this); } @EventBusListenerMethod protected void onSaveEvent(EditorSaveEvent e) { getDataProvider().refreshAll(); } }
  • 66. Session’s content • Dependency Injection (DI) Briefly • Setting up UI, ViewDisplay and Views a Beans • Navigation, ViewAccessControl • Securing with Spring Security • EventBus and other DI Extensions • Tips and Tricks for Springifying your Vaadin app
  • 67. S e t t i n g u p m e n u a u t o m a t i c a l l y @MenuDefinition(icon=, name=, order=) @SpringView(name=“customers”) public class CustomerViewBean implements View… { … }
  • 68. S e t t i n g u p m e n u a u t o m a t i c a l l y private void findAndPopulateMenuItems() { List<String> beanNames = Arrays.asList(context. getBeanNamesForAnnotation(MenuDefinition.class)); }
  • 69. S e t t i n g u p m e n u a u t o m a t i c a l l y private void findAndPopulateMenuItems() { List<String> beanNames = Arrays.asList(context. getBeanNamesForAnnotation(MenuDefinition.class)); Map<String, MenuDefinition> definitionsToNames = beanNames.stream(). collect(Collectors.toMap(Function.identity(), beanName -> context.findAnnotationOnBean(beanName, MenuDefinition.class))); Map<String, SpringView> viewsToNames = beanNames.stream(). collect(Collectors.toMap(Function.identity(), beanName -> context.findAnnotationOnBean(beanName, SpringView.class))); }
  • 70. S e t t i n g u p m e n u a u t o m a t i c a l l y private void findAndPopulateMenuItems() { List<String> beanNames = Arrays.asList(context. getBeanNamesForAnnotation(MenuDefinition.class)); Map<String, MenuDefinition> definitionsToNames = beanNames.stream(). collect(Collectors.toMap(Function.identity(), beanName -> context.findAnnotationOnBean(beanName, MenuDefinition.class))); Map<String, SpringView> viewsToNames = beanNames.stream(). collect(Collectors.toMap(Function.identity(), beanName -> context.findAnnotationOnBean(beanName, SpringView.class))); beanNames.forEach(beanName -> { MenuDefinition menuDefinition = definitionsToNames.get(beanName); SpringView viewDefinition = viewsToNames.get(beanName); addMenuItem(menuDefinition.name(), menuDefinition.icon(), viewDefinition.name()); });
  • 71. Va a d i n I 1 8 N S u p p o r t @EnableI18N
  • 72. Va a d i n I 1 8 N S u p p o r t @EnableI18N @Bean I18N i18n() { return new I18N(context); }
  • 73. Va a d i n I 1 8 N S u p p o r t @EnableI18N @Bean I18N i18n() { return new I18N(context); } @Bean CompositeMessageSource messageSource() { return new CompositeMessageSource(context); }
  • 74. Va a d i n I 1 8 N S u p p o r t @Bean MessageProvider provideTranslations() { return new ResourceBundleMessageProvider (“com.foo.path.to.bundle”, "UTF-8"); }
  • 75. P r o g r a m m a t i c B e a n L o o k u p @Component public class GenericBeanResolver { … }
  • 76. Lessons learned • DI is a powerful mechanism to decouple code • Following DI almost certainly guarantees that best practices are followed • Vaadin supports DI with Spring and CDI, both through their own integration addons • Lot of Spring functionality is based on Beans • Structuring Vaadin app with Bean approach can provide great flexibility and robustness
  • 77. T H A N K Y O U ! PLEASE RATE THE TALK @ FLIP CHART BY THE DOOR! @peter_lehto