Validating applications that use Contexts and Dependency Injection (CDI)

Your workspace provides in-line and quick-fix validations for contexts and dependency injection applications.

Before you begin

Create a Java EE-faceted project (that is, a utility project, or an EJB project or a Web project) in your workspace. For information about creating one of these projects see: Creating and configuring Java EE projects using wizards.

About this task

As-you-type validation is supported in CDI-faceted projects.

Procedure

  1. In the Java EE perspective, open your class that uses context and dependency injection annotations. If you add a new annotation, for example, @ApplicationScoped, and right-click on the Quick Fix icon, you can then add the required imports:
    CDI validation
    The import javax.enterprise.context.ApplicationScoped; import statement is added to your class.
  2. Scoped validation
    1. Validation is limited to the following built in CDI scope types:
      • @RequestScoped
      • @ApplicationScoped
      • @SessionScoped
      • @ConversationScoped
      • @Dependent
    2. Multiple scope declarations are not allowed on the bean class, producer methods, or producer fields. Validation flags this as an error and provides a Quick Fix to correct the problem.
    3. A subset of validators support the following passivating scopes:
      • @SessionScoped
      • @ConversationScoped
      These annotations can be declared on session beans and managed beans. In order for these beans to be passivating-enabled, they must conform to the rules:
      • Only Stateful Session Beans are passivating capable. Validation errors are issued if stateless or singleton annotated session beans are declared with one of these passivating scopes. Quick Fix support allows you to replace with the @Stateful annotation.
      • Managed Beans are passivating capable if the bean class, and all Interceptors and decorators, are serializable.
        Note: Validation flags an error if the bean class is not serializable and offers a Quick Fix to make it serializable. No validation is provided for Interceptors and Decorators.
  3. Type Restriction Validation A managed Bean has a set of legal bean types which include the java.lang.Object, the bean class, the superclass, and all interfaces it implements directly or indirectly. You can restrict the set of bean types by using the @Typed annotation but the restricted set must be a subset of the legal bean types set, otherwise a validation error will be issued. No Quick Fix support is provided for this.

Feedback