You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VaadinCDI.asciidoc 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ---
  2. title: Vaadin CDI
  3. order: 47
  4. layout: page
  5. ---
  6. [[vaadin-cdi]]
  7. = Vaadin CDI
  8. During these tutorials we will be solving a number of common problems
  9. when using the https://vaadin.com/directory/component/vaadin-cdi[Vaadin CDI plugin].
  10. The principal question we will be addressing is "How do I gain access to
  11. CDI features in a Vaadin project?"
  12. At the end of these tutorials you will have learned how to
  13. 1. Set up a Vaadin CDI project +
  14. 2. Create UI's and Views with Vaadin CDI +
  15. 3. Use injection with standard and Vaadin CDI scopes +
  16. 4. Pass events between various parts of your application +
  17. 5. Set up access control for your application
  18. We will assume familiarity with Vaadin 7 and common CDI concepts. As a
  19. reference development environment we'll be using
  20. http://www.eclipse.org/downloads/[Eclipse] Luna with the
  21. http://marketplace.eclipse.org/content/vaadin-plugin-eclipse[Vaadin
  22. plugin], Maven and http://tomee.apache.org/apache-tomee.html[TomEE].
  23. Installation and configuration of said environment is outside the scope
  24. of these tutorials.
  25. The tutorials will build off one another, each starting where the
  26. previous left off. If you wish to jump in at a later point feel free to
  27. get a copy of the project here: https://github.com/Vaadin/cdi-tutorial.
  28. The repository has tags for each tutorial's starting point, called
  29. tutorial-1 to tutorial-5.
  30. [[vaadin-cdi-for-the-impatient]]
  31. Vaadin CDI for the impatient
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. If you are eager to get started right away without following the
  34. tutorial, feel free to do so. There are still some *practical details*
  35. that are good to keep in mind if you're not familiar with
  36. https://vaadin.com/directory/component/vaadin-cdi[Vaadin CDI features] or CDI in
  37. general.
  38. * *Use http://tomee.apache.org/downloads.html[TomEE Web Profile]* or
  39. some other JavaEE 6+ *server*. Tomcat or Jetty won't work out of the
  40. box.
  41. ** *Add the http://mvnrepository.com/artifact/javax/javaee-api[JavaEE
  42. API] to your classpath* if e.g. the @Inject annotation can't be
  43. found. Depending on how your project is configured, this might not be
  44. necessary and might in some cases even cause conflicts. +
  45. * *Objects must be injected* and managed by the CDI implementation in
  46. order to use CDI features.
  47. ** *Use @Inject on an instance field* to make the CDI implementation
  48. inject a managed instance of the corresponding type.
  49. ** *Annotate your UI class with @CDIUI("")* to let Vaadin CDI know that
  50. it should inject and use instances of that class when the application is
  51. opened in the browser.
  52. ** *Remove any existing VaadinServlet* from your project (look for
  53. servlets with @WebServlet or defined in web.xml). Vaadin CDI has its own
  54. VaadinCDIServlet that will be deployed automatically as long as no other
  55. Vaadin servlets are present.
  56. ** *Initialize objects in a method annotated with @PostConstruct.* CDI
  57. features such as @Inject are not yet functional when the constructor is
  58. run.
  59. [[related-pages]]
  60. Related pages
  61. ~~~~~~~~~~~~~
  62. <<IIInjectionAndScopes#ii-injection-and-scopes,"II - Injection and scopes">>