]
Priya M commented on SEAMFACES-82:
----------------------------------
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.
Injection in faces Converters broken
------------------------------------
Key: SEAMFACES-82
URL:
https://issues.jboss.org/browse/SEAMFACES-82
Project: Seam Faces
Issue Type: Bug
Components: CDI Integration
Affects Versions: 3.0.0.Beta2
Environment: jboss AS 6 final, windows, war deployment
Reporter: yangju
Assignee: Brian Leathem
Priority: Critical
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;
}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: