2 Replies Latest reply on Feb 8, 2010 8:59 AM by Gavin King

    Bean types in Weld: "client-visible"

    Alexandros Karypidis Novice

      Weld reference, page 8 (emphasis mine):

      A bean type is a user-defined class or interface; a type that is client-visible. If the bean is an EJB session bean, the
      bean type is the @Local interface or bean-class local view.

      So, regarding client-visible: who is the client and when is a type visible by the client?

      I assume any code that interacts with the container for injection is a client. I also assume that a type is visible by the client if it is in its classpath. I'm also pretty certain that my assumptions are wrong, so I need someone to enlighten me:

      IF that were the case, the bean type is not absolute, but rather depends on the client perspective. One can't make hard statements on which types are bean types or not, as that would depends on the classloader active during code execution of the client code.

      So my interpretation must be wrong, as the reference immediately goes on to make hard statements like:

      Meanwhile, this session bean has only the local interfaces BookShop, Auditable and java.lang.Object as bean types, since the bean class, BookShopBean is not a client-visible type.

      public class BookShopBean
          extends Business
          implements BookShop, Auditable {

      Can someone enlighten me as to what it is that I've misunderstood?

        • 1. Re: Bean types in Weld: "client-visible"
          Matthieu Chase Heimer Newbie

          The bean types are the valid Java class and interface types that you can use in your references.

          So with @Inject BizInt ref; the BizInt must be a valid bean type.

          The types that are valid for a bean are normally the bean class, all parent classes (including Object), and all interface types.

          You can restrict the valid types by using the @Typed annotation in the managed bean. Given the following class and the implied interface:

          public class AccountJPA_DAO implements AccountDAO {}

          The client could:

          @javax.inject.Inject AccountDAO dao;

          The client could not: (exception at runtime)

          @javax.inject.Inject AccountJPA_DAO dao;

          The thing about the example you quote is that it is an EJB example and the EJB spec says that when a session bean has a biz interface(s) you must use that as the type. So the bean class not being a valid type with an EJB is just because the session bean has a biz interface. But you have no-interface view session beans and you can add @LocalBean to the session bean re-enable the no-interface view if you have biz interfaces. I'm sure that in the case of a no-interface view session bean that the bean class would be a valid type.

          • 2. Re: Bean types in Weld: "client-visible"
            Gavin King Master

            So, regarding "client-visible": who is the client and when is a type visible by the client?

            The client is the code that calls the bean. The client-visible types of a bean depend upon what kind of thing the bean is. If it is an EJB, for example, the bean class itself might not be visible to the client (as defined by the EJB spec). If it is a resource, then the implementation class is not visible to the client, only the standard EntityManager, Datasource, etc, interface that it implements.