Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 3.0.0.Beta2
    • Fix Version/s: None
    • Component/s: CDI Integration
    • Labels:
      None
    • Environment:
      jboss AS 6 final, windows, war deployment
    • Steps to Reproduce:
      Hide

      add multiple modules into the war (most importantly, persistence, solder)

      Show
      add multiple modules into the war (most importantly, persistence, solder)

      Description

      I have a big war with seam 3 faces, persistence, internationalization, xml config, solder modules in the web-inf/lib.
      I have tried to inject managed beans into the jsf converter, but it does not matter it is my own bean or seam's bean or weld's bean, the bean is always null. It seems that the injection fails silently. The converter code is as follows:
      package com.pearson.epen.managedBean.converter;

      import java.io.Serializable;
      import java.util.List;

      import javax.annotation.PostConstruct;
      import javax.enterprise.context.SessionScoped;
      import javax.faces.component.UIComponent;
      import javax.faces.context.FacesContext;
      import javax.faces.convert.Converter;
      import javax.faces.convert.FacesConverter;

      import javax.inject.Inject;
      import javax.persistence.EntityManager;

      import org.slf4j.Logger;

      import com.pearson.epen.account.model.api.TestAdmin;
      import com.pearson.epen.cdi.qualifier.CentralRepo;
      import com.pearson.epen.cdi.qualifier.StaticData;

      @SessionScoped
      @FacesConverter("convert.TestAdmin")
      public class TestAdminConverter implements Converter, Serializable {

      private static final long serialVersionUID = 1L;

      @Inject
      @StaticData
      private List<TestAdmin> admins;

      @Inject
      private FacesContext context;

      @Inject
      @CentralRepo
      private EntityManager em;
      @Inject
      private Logger log;

      @PostConstruct
      public void init()

      { log.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%init"); }

      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
      try {

      Long id = Long.valueOf(value);
      for (TestAdmin admin : admins) {
      if (admin.getId().longValue() == id.longValue())

      { return admin; }

      }
      } catch (Throwable t)

      { log.error("got exception", t); }

      return null;
      }

      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value)

      { TestAdmin testAdmin = (TestAdmin) value; return Long.toString(testAdmin.getId()); }

      }

      In above code, all injections are null and the @PostConstruct method is never called. However, getAsObject(FacesContext context, UIComponent component, String value) and getAsString(FacesContext context, UIComponent component, Object value) did get called.

      According to some other users, the injection works for them. But I am not sure they have multiple seam modules being used in the same war.

      Our war is big and it is difficult to isolate our application to just use seam faces, not others. So I am not creating a sample war. But it should be easy for seam faces developer to test this.

      I ended up doing bean lookup in my converter and it seems working and the bean is found in my converter.

      public List<T> findBeanRef(FacesContext context, String beanELName)

      { BeanManager bm = (BeanManager) (((ServletContext) context.getExternalContext().getContext()) .getAttribute("org.jboss.seam.faces.javax.enterprise.spi.BeanManager")); Bean bean = bm.getBeans(beanELName).iterator().next(); CreationalContext ctx = bm.createCreationalContext(bean); List<T> list = (List<T>) bm.getReference(bean, bean.getClass(), ctx); return list; }

        Gliffy Diagrams

          Activity

          Hide
          bleathem Brian Leathem added a comment -

          I created a simple test case, and confirmed that @Inject is not working for Faces Converters.

          Some Background:
          The class SeamApplicationWrapper is responsible for making sure the @Inject annotations gets resolved. It does this by intercepting the creation of a Converter, and replacing the JSF instantiated Converter with one retrieved from the BeanManager.

          The problem:
          This interception is indeed working, and SeamApplicationWrapper is invoking the BeanManager to return a managed Converter instance, but the BeanManager lookup is failing, returning a null result. The root cause of this is that BeanManager.getBeans(type) returns an empty set, when type is a Faces Converter class.

          Going to have to get some Weld help to resolve this further.

          Show
          bleathem Brian Leathem added a comment - I created a simple test case, and confirmed that @Inject is not working for Faces Converters. Some Background: The class SeamApplicationWrapper is responsible for making sure the @Inject annotations gets resolved. It does this by intercepting the creation of a Converter, and replacing the JSF instantiated Converter with one retrieved from the BeanManager. The problem: This interception is indeed working, and SeamApplicationWrapper is invoking the BeanManager to return a managed Converter instance, but the BeanManager lookup is failing, returning a null result. The root cause of this is that BeanManager.getBeans(type) returns an empty set, when type is a Faces Converter class. Going to have to get some Weld help to resolve this further.
          Hide
          bleathem Brian Leathem added a comment -

          Worked through this some with Stuart Douglas, we demonstrated the BeanManager lookup of the Faces Converter class works from within the test web application. Since the lookup works from within the test app, Stuart figures this is a BDA (bean deployment archive) visibility problem.

          See the WELD-846 (https://issues.jboss.org/browse/WELD-846)

          Show
          bleathem Brian Leathem added a comment - Worked through this some with Stuart Douglas, we demonstrated the BeanManager lookup of the Faces Converter class works from within the test web application. Since the lookup works from within the test app, Stuart figures this is a BDA (bean deployment archive) visibility problem. See the WELD-846 ( https://issues.jboss.org/browse/WELD-846 )
          Hide
          bleathem Brian Leathem added a comment -

          I tested Stuart's patch for WELD-846, and it resolves this problem. We now just have to wait for a Weld release, and for that release to make it into the respective containers.

          Show
          bleathem Brian Leathem added a comment - I tested Stuart's patch for WELD-846 , and it resolves this problem. We now just have to wait for a Weld release, and for that release to make it into the respective containers.
          Hide
          bleathem Brian Leathem added a comment -

          While this issue is being resolved in WELD-846, it is a failing on the part of Seam Faces to have failed silently. To resolve this, I've added a logger to SeamApplicationWrapper to provide a warning message when extension of Converters and Validators fails. I also added a number of debug messages to allow for troubleshooting.

          Show
          bleathem Brian Leathem added a comment - While this issue is being resolved in WELD-846 , it is a failing on the part of Seam Faces to have failed silently. To resolve this, I've added a logger to SeamApplicationWrapper to provide a warning message when extension of Converters and Validators fails. I also added a number of debug messages to allow for troubleshooting.
          Hide
          infinity2heaven Priya M added a comment -

          I have the same issue. Using JBoss AS 6.1.SNAPSHOT (Feb 9th 2011) and Mojarra-2.1.0-b11.

          Converter is very similar to the one in this issue. In my case I'm trying to inject a @PersistentContext @Log @UserService – all are null.

          Show
          infinity2heaven Priya M added a comment - I have the same issue. Using JBoss AS 6.1.SNAPSHOT (Feb 9th 2011) and Mojarra-2.1.0-b11. Converter is very similar to the one in this issue. In my case I'm trying to inject a @PersistentContext @Log @UserService – all are null.
          Hide
          bleathem Brian Leathem added a comment -

          @Priya: This is a WELD issue, and has been fixed in Weld. It's a matter of waiting until the patched Weld (will be Weld 1.2 I believe) makes it into your preferred application server.

          In the mean time, you can find out how to replace the Weld implementation in your container with a Weld SNAPSHOT you can build yourself. I can tell you how to do this for Glassfish, but I do not know how for JBoss AS.

          Show
          bleathem Brian Leathem added a comment - @Priya: This is a WELD issue, and has been fixed in Weld. It's a matter of waiting until the patched Weld (will be Weld 1.2 I believe) makes it into your preferred application server. In the mean time, you can find out how to replace the Weld implementation in your container with a Weld SNAPSHOT you can build yourself. I can tell you how to do this for Glassfish, but I do not know how for JBoss AS.
          Hide
          bleathem Brian Leathem added a comment -

          Fixed in WELD-846

          Show
          bleathem Brian Leathem added a comment - Fixed in WELD-846

            People

            • Assignee:
              bleathem Brian Leathem
              Reporter:
              yangju Richard Yang
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development