javacro'14 - vaadin web application integration for enterprise systems – peter lehto
Upload: hujak-hrvatska-udruga-java-korisnika-croatian-java-user-association
Post on 10-May-2015
1.925 views
DESCRIPTION
Vaadin is Java framework for rapid development of highly interactive HTML5-based web applications. Because of server-driven nature Vaadin can easily be integrated with server-side Java EE features such as EJBs and JPA. During this speech we will look in detail on how multi-view Vaadin applications are built and coupled with Java EE based business systems using Context and Dependency Injection (CDI). Important topics covered within the session are the best practices of developing Model-View-Presenter (MVP) based Vaadin views as well as the as pointers and guidelines on how to use Vaadin with Java EE. Attending the speech does not require thorough understanding of Java EE or web technologies in general.TRANSCRIPT
![Page 1: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/1.jpg)
Vaadin 7Enterprise integration
Peter Lehto Vaadin Expert
![Page 2: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/2.jpg)
MVP
pattern
Structuring
Vaadin
Application
Views with
Vaadin
Navigator
![Page 3: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/3.jpg)
UIProvider
CDIViewProviderVaadin-CDI
@Inject, @EJB
![Page 4: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/4.jpg)
How to
get started?
QA
Context and
Scope
Authentication
and
Authorization
![Page 5: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/5.jpg)
MVP pattern
![Page 6: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/6.jpg)
Do you like spaghetti?
MVP pattern
![Page 7: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/7.jpg)
What is MVP?
MVP pattern
![Page 8: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/8.jpg)
Originally Model-View-Controller
Originates from late 70’s
SmallTalk-80
Controller is mediator between end user and application
Model notifies about changes with Observer pattern
MVP pattern
![Page 9: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/9.jpg)
Taligent Model-View-Presenter
Influenced by SmallTalk-80
Model, View, Presenter, Interactors, Commands, Selections
Presenter orchestrates the structure, not the input
MVP pattern
![Page 10: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/10.jpg)
Dolphin Smalltalk Model-View-Presenter
Simplified Taligent MVP
Views handle input events initially
Model may fire events
Presenter handles the logic, not the user input control
MVP pattern
![Page 11: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/11.jpg)
Model-View-Presenter
Presenter
View Model
Direct Association
Indirect Association
MVP pattern
![Page 12: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/12.jpg)
“That’s not how you use MVP!”
MVP pattern
![Page 13: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/13.jpg)
Model-View-Presenter
Presenter
Model
View Impl
View
MVP pattern
![Page 14: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/14.jpg)
What is the role of the Presenter?
MVP pattern
![Page 15: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/15.jpg)
Structuring
Vaadin
Application
![Page 16: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/16.jpg)
Example
EditorView
- Button saveButton;!- Button cancelButton;!- FieldGroup personFieldGroup;
- saveButtonClicked()!- cancelButtonClicked()
ClickListener
+ buttonClicked()
Structuring
Vaadin
Application
![Page 17: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/17.jpg)
EditorView
- Button saveButton;!- Button cancelButton;!- FieldGroup personFieldGroup;
ClickListener
Presenter
+ saveButtonClicked()!+ cancelButtonClicked()!
+ buttonClicked()
+ commitChanges()!+ discardChanges()
ExampleStructuring
Vaadin
Application
![Page 18: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/18.jpg)
EditorView+ commitChanges()!+ discardChanges()
Example
EditorView
- Button saveButton;!- Button cancelButton;!- FieldGroup personFieldGroup;
ClickListener
Presenter
+ saveButtonClicked()!+ cancelButtonClicked()!
+ buttonClicked()
+ commitChanges()!+ discardChanges()
Structuring
Vaadin
Application
![Page 19: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/19.jpg)
Benefits of MVP
Allows you to create unit and integration tests for your UI logic
Abstracts your code to be more reusable
Your UI logic is separated from the UI implementation
Structuring
Vaadin
Application
![Page 20: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/20.jpg)
Views with
Vaadin
Navigator
![Page 21: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/21.jpg)
Navigator
Support for bookmarkable views and browser navigation
Automatic URI fragment handling
Built-in switching between views
Views with
Vaadin
Navigator
![Page 22: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/22.jpg)
public class DashboardView extends CustomComponent implements
com.vaadin.navigator.View
Views with
Vaadin
Navigator
![Page 23: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/23.jpg)
public class MyNavigatorUI extends UI{!! @Override!! Protected void init(VaadinRequest request){!! ! Navigator navigator = new Navigator(this, this); !! ! navigator.addView(“dashboard”, new DashboardView());!! } !}!
Views with
Vaadin
Navigator
![Page 24: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/24.jpg)
Activating a view programmatically
UI.getCurrent().getNavigator().navigateTo("customers");
Views with
Vaadin
Navigator
![Page 25: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/25.jpg)
http://localhost:8080/vaadin/#!customers !
#! : Navigator identifier customers : View name
Navigating to a view via URLViews with
Vaadin
Navigator
![Page 26: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/26.jpg)
...but where is the view rendered?
Views with
Vaadin
Navigator
![Page 27: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/27.jpg)
Views with
Vaadin
Navigator
![Page 28: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/28.jpg)
public Navigator(UI ui, ComponentContainer container)public Navigator(UI ui, SingleComponentContainer container)
public Navigator(UI ui, ViewDisplay viewDisplay)
Views with
Vaadin
Navigator
![Page 29: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/29.jpg)
Vaadin-CDI
![Page 30: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/30.jpg)
Context and Dependency Injection
(JSR-299)
Vaadin-CDI
![Page 31: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/31.jpg)
Injection
!
Context and Scope
!
Events
!
Decoupling
CDIVaadin-CDI
![Page 32: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/32.jpg)
Features
Vaadin UI based context scope
!
Vaadin Navigator Integration
!
Easy JAAS Integration
!
Role Based View Management
Vaadin-CDI
![Page 33: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/33.jpg)
@CDIUI public class MyVaadinUI extends UI
Vaadin-CDI
http://localhost:8080/vaadin/
![Page 34: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/34.jpg)
@CDIUI(“myui”) public class MyVaadinUI extends UI
Vaadin-CDI
http://localhost:8080/vaadin/myui
![Page 35: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/35.jpg)
@CDIUI public class MyVaadinUI extends UI { @Inject private MyBean bean; … }
Vaadin-CDI
![Page 36: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/36.jpg)
@CDIUI public class MyVaadinUI extends UI { !
@EJB private MyServiceEJB service; … }
Vaadin-CDI
![Page 37: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/37.jpg)
@CDIUI public class MyVaadinUI extends UI { !
@Inject private javax.enterprise.event.Event<MyEvent> myEvent; … myEvent.fire(new MyEvent()); }
Vaadin-CDI
![Page 38: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/38.jpg)
@CDIUI public class MyVaadinUI extends UI { … !
protected void onMyEvent(@Observes MyEvent myEvent) { } }
Vaadin-CDI
![Page 39: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/39.jpg)
@CDIView(“customers”) public class CustomerView extends CustomComponent implements View
Vaadin-CDI
http://localhost:8080/vaadin/#!customers
![Page 40: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/40.jpg)
UIProvider
CDIViewProvider
![Page 41: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/41.jpg)
@CDIUI public class MyVaadinUI extends UI { !
@Inject private CDIViewProvider viewProvider; … navigator.addProvider(viewProvider); }
UIProvider
CDIViewProvider
![Page 42: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/42.jpg)
UIProvider
CDIViewProvider
public class CDIViewProvider implements ViewProvider {! @Inject private BeanManager beanManager;! @Inject private AccessControl accessControl;! …! public String getViewName(String) { … } public View getView(String) { … }}
![Page 43: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/43.jpg)
UIProvider
CDIViewProvider
public class CDIUIProvider extends DefaultUIProvider {! public UI createInstance(UICreateEvent event) { … } public Class<? extends UI> getUIClass (UIClassSelectionEvent event) { … }}
![Page 44: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/44.jpg)
UIProvider
CDIViewProvider ContextDeployer
@WebListener
!
Is capable of bootstrapping Vaadin Servlet with CDIUIProvider
!
Will validate deployment
![Page 45: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/45.jpg)
Context and
Scope
![Page 46: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/46.jpg)
Context and
Scope VaadinServlet
HttpSession VaadinSession
UI
1
n
1 1
1
n
1
*
EJB
1*
View/Presenter
1
*
![Page 47: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/47.jpg)
Context and
Scope UIScope
Necessary to acquire UI specific component injections
!
CDI context to map beans per UI instance
!
@UIScoped
![Page 48: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/48.jpg)
Context and
Scope UIScope
@CDIUI and @CDIView are @Stereotypes with @UIScoped
!
CDI events are sent within the scope
!
MVP Presenters and UI specific resources are marked as @UIScoped
![Page 49: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/49.jpg)
Authentication
and
Authorization
![Page 50: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/50.jpg)
Authentication
and
Authorization
com.vaadin.cdi.access. AccessControl
@RolesAllowed
!
isUserSignedIn(), isUserInRole(String),
getPrincipalName()
!
Can be replaced with @Alternative
![Page 51: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/51.jpg)
How to
get started?
![Page 52: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/52.jpg)
<dependency <groupId>com.vaadin</groupId> <artifactId>vaadin-cdi</artifactId> <version>1.0.0.alpha2</version></dependency>!<dependency org="com.vaadin" name="vaadin-cdi” rev=“1.0.0.alpha2” conf="default->default" />
How to
get started?
![Page 53: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/53.jpg)
Eclipse
Download plugin from Martketplace
How to
get started?
![Page 54: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/54.jpg)
IntelliJ IDEA
Built-in support
How to
get started?
![Page 55: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/55.jpg)
Netbeans
Download plugin Netbeans Plugin Portal
How to
get started?
![Page 56: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/56.jpg)
mvn archetype:generate
-DarchetypeGroupId=
com.vaadin
-DarchetypeArtifactId=
vaadin-archetype-application
-DarchetypeVersion=
7.1.15
Maven
How to
get started?
![Page 57: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/57.jpg)
Questions or Comments?
![Page 58: JavaCro'14 - Vaadin web application integration for Enterprise systems – Peter Lehto](https://reader033.vdocuments.site/reader033/viewer/2022052618/554f4b39b4c905524c8b497e/html5/thumbnails/58.jpg)
3
Vaadin: A Familiar Way to Build Web Apps with Java
DZone, Inc. | www.dzone.comFigure 4: The Class Diagram presents all user interface component classes and the most important interfaces, relationships, and methods.
Questions or Comments?