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:
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()
@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())
}
} catch (Throwable t)
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value)
}
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; }
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.