Directory

← Back

Vaadin CDI

Contexts and Dependency Injection for Vaadin

Author

Rating

Popularity

100+

This add-on permits the use of primary CDI (JSR-299) features such as dependency injection, CDI events, etc. It also defines a new CDI scope for UIs and automatically configures a servlet for CDI if no Vaadin servlets are defined.

Compatibility

Vaadin CDI Vaadin version
1.x 7.x
2.x 8.0..8.1
3.x 8.2..
10.0.x 10
11.0.x 14

Getting started

Startup

If you do not customize Vaadin Servlet in your web.xml, a CDI enabled Vaadin servlet is deployed automatically.

As UI class CdiUI is configured. If you need a custom UI class, you have to extend this class. It is not a CDI contextual instance but injects work.

Otherwise, you can customize CdiVaadinServlet just like VaadinServlet.

Component instantiation and CDI

Vaadin triggered instantiation happens in a CDI aware Vaadin Instantiator implementation. Components created by this API:

  • @Route, RouteLayout, HasErrorParameter components
  • component fields injected by @Id to polymer templates

By default, instantiator looks up the CDI bean by type ( component class )
and gets a contextual reference from BeanManager. All the CDI features are usable like observer, interceptor, decorator.

When type is not found as a CDI bean ( for example ambiguous, or does not have a no-arg public constructor ), instantiation falls back to the default Vaadin behavior. On success, dependency injection is performed. Injects work, but other CDI features not. It is not a contextual instance.

Vaadin Contexts

In addition to standard CDI contexts, the CDI add-on introduces some new contexts. Read more about the supported scopes in Vaadin Docs

Services

Some Vaadin service interfaces can be implemented as a CDI bean.

  • I18NProvider
  • Instantiator
  • SystemMessagesProvider
  • ErrorHandler

Beans have to be qualified by @VaadinServiceEnabled to be picked up automatically.

Example code is available in Vaadin Docs

Vaadin Events

Following events fired as a CDI event:

  • ServiceInitEvent
  • PollEvent
  • BeforeEnterEvent
  • BeforeLeaveEvent
  • AfterNavigationEvent
  • UIInitEvent
  • SessionInitEvent
  • SessionDestroyEvent
  • ServiceDestroyEvent

See example code in Vaadin Docs

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

the official Flow CDI integration that is compatible with Vaadin 14.

Released
2019-07-29
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 14+
Vaadin 10+ in 10.0.0
Vaadin 8.2+ in 3.0.1
Vaadin 7.7+ in 1.0.4
Vaadin 8.1+ in 3.0.0.alpha1
Vaadin 8.0+ in 2.0.0
Vaadin 7.3+ in 1.0.5
Vaadin 7.2+ in 1.0.0.alpha3
Vaadin 7.0+ in 1.0.0.alpha1
Browser
Browser Independent

Vaadin CDI - Vaadin Add-on Directory

Contexts and Dependency Injection for Vaadin Vaadin CDI - Vaadin Add-on Directory
This add-on permits the use of primary CDI (JSR-299) features such as dependency injection, CDI events, etc. It also defines a new CDI scope for UIs and automatically configures a servlet for CDI if no Vaadin servlets are defined. ## Compatibility | Vaadin CDI | Vaadin version | | ------------- |:-------------:| | 1.x | 7.x | | 2.x | 8.0..8.1 | | 3.x | 8.2.. | | 10.0.x | 10 | | 11.0.x | 14 | ## Getting started ### Startup If you do not customize Vaadin Servlet in your web.xml, a CDI enabled Vaadin servlet is deployed automatically. As UI class CdiUI is configured. If you need a custom UI class, you have to extend this class. It is not a CDI contextual instance but injects work. Otherwise, you can customize CdiVaadinServlet just like VaadinServlet. ## Component instantiation and CDI Vaadin triggered instantiation happens in a CDI aware Vaadin Instantiator implementation. Components created by this API: - @Route, RouteLayout, HasErrorParameter components - component fields injected by @Id to polymer templates By default, instantiator looks up the CDI bean by type ( component class ) and gets a contextual reference from BeanManager. All the CDI features are usable like observer, interceptor, decorator. When type is not found as a CDI bean ( for example ambiguous, or does not have a no-arg public constructor ), instantiation falls back to the default Vaadin behavior. On success, dependency injection is performed. Injects work, but other CDI features not. It is not a contextual instance. ## Vaadin Contexts In addition to standard CDI contexts, the CDI add-on introduces some new contexts. Read more about the supported scopes in [Vaadin Docs](https://vaadin.com/docs/flow/cdi/tutorial-cdi-contexts.html) ## Services Some Vaadin service interfaces can be implemented as a CDI bean. - I18NProvider - Instantiator - SystemMessagesProvider - ErrorHandler Beans have to be qualified by @VaadinServiceEnabled to be picked up automatically. Example code is available in [Vaadin Docs](https://vaadin.com/docs/flow/cdi/tutorial-cdi-service-beans.html) ## Vaadin Events Following events fired as a CDI event: - ServiceInitEvent - PollEvent - BeforeEnterEvent - BeforeLeaveEvent - AfterNavigationEvent - UIInitEvent - SessionInitEvent - SessionDestroyEvent - ServiceDestroyEvent See example code in [Vaadin Docs](https://vaadin.com/docs/flow/cdi/tutorial-cdi-events.html)
Author Homepage
Issue Tracker
Source Code
Tutorial
Java EE Compatibility Matrix

Vaadin CDI version 1.0.0.alpha1
null

Vaadin CDI version 1.0.0.alpha2
Fixes three critical bugs relating to closing UIs or VaadinSessions.

Vaadin CDI version 1.0.0.alpha3
Main changes include - Reintroduce conventions for mapping of views and UIs - This requires updating @CDIUI and @CDIView parameter values in existing applications - see http://dev.vaadin.com/ticket/12385 for details - @UIScoped is inherited by subclasses of an annotated UI - Support non-JEE containers with Weld (BeanManager look-up) - Automatically injected servlet has async-supported enabled - See http://dev.vaadin.com/query?status=closed&milestone=Vaadin+CDI+1.0.0.alpha3 for the complete list of changes.

Vaadin CDI version 1.0.0.beta1
- @ViewScoped context - @UIScoped and @ViewScoped use @NormalScope, supporting interceptors etc. - Better support for server push (including WebSockets) and operations in background threads (within UI.access()) - DeltaSpike library is used internally by the add-on - Various fixes and small enhancements - See http://dev.vaadin.com/query?status=closed&status=released&milestone=Vaadin+CDI+1.0.0.beta1 for the complete list of changes. Note that injecting components requires Vaadin 7.3.1 or later. Other functionality requires Vaadin 7.2 or later.

Vaadin CDI version 1.0.0.beta2
- @UIScoped and @ViewScoped can be used on methods (producer methods, setter injection, constructor injection) - Dependency on Guava eliminated - Various fixes including - UI and View are now correctly included in their own scopes - Sub-views with slash in view name are now handled correctly

Vaadin CDI version 1.0.0.beta3
- breaking change: @UIScoped and @ViewScoped are no longer @NormalScope - added corresponding @NormalUIScoped and @NormalViewScoped - breaking change: NormalScopes (including @NormalUIScoped and @NormalViewScoped) are not supported classes implementing com.vaadin.ui.Component

Vaadin CDI version 1.0.0.beta4
Do not block the use of components in normal scopes (@NormalUIScope, @NormalViewScope)

Vaadin CDI version 1.0.0.rc1
- moved the classes VaadinCDIServlet and VaadinCDIServletService to the package com.vaadin.cdi.servlet - do not add hyphens within all caps abbreviations in automatic UI/view names, e.g. MyCDIUI becomes my-cdi and MyCDITestView becomes my-cdi-test - added check at deployment time: classes with @CDIView must implement View - added check at deployment time: if a servlet class is nested in a UI with @CDIUI, it must extend VaadinCDIServlet

Vaadin CDI version 1.0.0
No changes since 1.0.0.rc1

Vaadin CDI version 1.0.1
Upgrade to DeltaSpike 1.0.3 for GlassFish 4.1 compatibility

Vaadin CDI version 1.0.2
null

Vaadin CDI version 1.0.3
Upgrade to DeltaSpike 1.4.1. In case of compatibility problems, an explicit dependency to DeltaSpike 1.3.0 can be used in the project POM to override the dependency.

Vaadin CDI version 2.0.0.beta1
Vaadin CDI add-on for Vaadin Framework 8.0.0.beta1 Available from the pre-releases repository, i.e. for maven: ```xml vaadin-prereleases https://maven.vaadin.com/vaadin-prereleases ```

Vaadin CDI version 2.0.0.rc1
Compatible with Vaadin Framework 8.0.0.rc1

Vaadin CDI version 2.0.0
Compatible with Vaadin Framework 8.0. Fix for UI cleanup within session.

Vaadin CDI version 3.0.0.alpha1
See https://github.com/vaadin/cdi/releases/tag/3.0.0.alpha1

Vaadin CDI version 1.0.4
Fix closed UI cleanup. Open CDIViewProvider methods getViewBean() and parseViewName() for extension. Update DeltaSpike to 1.7.2.

Vaadin CDI version 3.0.0
See [release notes](https://github.com/vaadin/cdi/releases/tag/3.0.0) at GitHub.

Vaadin CDI version 1.0.5
1.0.5 has following fixes: - Improvements in the closed `UI` cleanup - `@PreDestroy` is now called properly - Fix `VaadinServlet` detection with Liberty, JAX-WS and JAX-RS In this version there is a possible issue still in `UI` cleanup with WELD.

Vaadin CDI version 3.0.1
3.0.1 has following fixes: - Add context path to UI path info - Fix deploying with JAX-WS, JAX-RS Liberty

Vaadin CDI version 10.0.0
This is the first stable release for CDI for Vaadin 10+.

Vaadin CDI version 11.0.0
the official Flow CDI integration that is compatible with Vaadin 14.

Online