JBoss.orgCommunity Documentation

CDI Tools Reference Guide

Version: 4.0.0


1. Introduction to CDI tooling
2. Creating a CDI Web Project
3. Adding CDI Support to a project
4. Wizards and Dialogs
4.1. Wizards
4.2. Dialogs
4.2.1. Open CDI Named Bean
5. Validation
6. Hyperlink navigation
A. Revision History

Context and Dependency Injection (CDI) tooling allows you to easily add and work with the CDI programming model for your web-based applications. This guide demonstrates how to add CDI to existing projects and create new projects with the CDI wizard. For information on the specifics of CDI outside of the tooling, see http://jcp.org/en/jsr/detail?id=299.

From the workbench go to FileNewOther.


The first screen of the wizard will ask you to define the attributes according to the options outlined in Table 2.1, “New CDI Web Project”. Click the Next button after defining the attributes in order to continue customizing your project or click the Finish button to accept all other defaults and create your application.


Table 2.1. New CDI Web Project

FieldMandatoryInstructionDescription
Project nameyesEnter a project name.The project name can be any name you define.
Project locationyesThe Use default location checkbox will be selected automatically to define the project location as the Eclipse workspace. However you can define a custom path in the Location field be deselecting the Use default location checkbox.The default location corresponds to the Eclipse workspace.
Target runtimenoSelect a pre-configured runtime from the available options or configure a new runtime environment.

The target runtime defines the server to which the application will be deployed.

Dynamic web module versionyesSelect the required web module version.

This option adds support for the Java Servlet API with module versions corresponding to JEE or J2EE levels as listed in Table 2.2, “New CDI Web Project - Dynamic web module version”.

ConfigurationyesSelect the project configuration from the available options.

The project can be based on either a custom or a set of pre-defined configurations as described in Table 2.3, “New CDI Web Project - Configuration”.

EAR membershipnoAdd the project to an existing EAR project.

The project can be added to an existing EAR project by selecting the checkbox. Once checked, a new EAR project can be defined by clicking the New Project button.

Working setsnoAdd the project to an existing working set.

A working set provides the ability to group projects or project attributes in a customized way to improve access. A new working set can be defined once the Select button has been clicked.




The Java configuration screen allows you to define Source folders on the build path and the Default output folder. The defaults for each are recommended, however you have the option to change them as you see fit.


The Web Module configuration screen allows you to define the Context root and the Content directory to be created, the option to Generate web.xml deployment descriptor is selected by default. The defaults for each are recommended, however you have the option to change them as you see fit.


The Context and Dependency Injection (CDI) Facet settings configuration screen allows you to Generate beans.xml file, selected by default. The beans.xml file is a bean archive descriptor that allows you to enable CDI services for a bean archive. It is recommended that you leave the option selected.


The final screen of the wizard pertains to JSF Capabilities configuration.





Click the Finish button to create your CDI Web Project.

CDI support can be added either to an existing project or during project creation.

To add CDI support to an existing project, select the project, and right-click to bring up the context menu. From the menu select ConfigureAdd CDI support. The following preferences page will now display:


You can also add CDI support to a project during project creation. To do so, click the Modify button beside the selected Configuration on the first screen of the project wizard.


From the Project Facets screen, add CDI to the project by selecting the checkbox beside the facet CDI (Contexts and Dependency Injection) . Click the OK button to accept the configuration change and return to the project creation wizard.


CDI validation covers nearly all of the rules declared in the JSR-299 specification. For every type of validation rule, you can set if it should be interpreted as an error, warning or just ignored. This is achieved by navigating to WindowPreferencesJBoss ToolsCDICDI Validator.


The CDI validator can check JSP, XHTML, beans.xml and java source files. Some validation issues can be fixed through the Quick Fixes menu (Ctrl+1).


Hyperlinks (OpenOn integration) allows you to quickly navigate between source files. Pressing Ctrl+Left-Click or F3 on any expression language (EL) declaration will navigate you to the corresponding java source.

CDI Tools offers you a list of navigation alternatives for the bean that will be injected.


If multiple eligible beans are detected for the injection, you will see an option to Show All Assignable Beans.


Selecting this option will display a dialog containing all eligible beans.


Corresponding classes and interfaces that are mentioned in beans.xml can be opened through pressing Ctrl+Left-Click on the type name.

Observers and Events can be navigated to through the same method as well; Show CDI Observer Methods and Show CDI Events.



Producer and Disposer methods, if available, will appear in the context menu for an injection.



Revision History
Revision 1-0Fri Jan 06 2012Isaac Rooskov
Initial creation of book