Environment:
- Wildfly 22
- Java 11
- JSF 2.3
I have created a @FacesConverter managed=true but when I try to @Inject a @Stateless class I get null.
face.xhtml
...
<h:outputText value="#{workBean.work.type.name}" rendered="#{!workBean.editable}"/>
<p:selectOneMenu id="cbxType" value="#{workBean.work.type}"
required="true" requiredMessage="#{msgs.wrk_reqtype}"
converter="workTypeConverter"
rendered="#{workBean.editable}">
<f:selectItem itemLabel="#{msgs.select}" itemValue="#{null}" noSelectionOption="false" />
<f:selectItems value="#{workBean.types}" var="t"
itemValue="#{t}" itemLabel="#{t.name}"/>
</p:selectOneMenu>
...
WorkTypeConverter
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import java.time.format.DateTimeParseException;
@FacesConverter(value = "workTypeConverter", managed = true)
public class WorkTypeConverter implements Converter {
@Inject
WorkTypeManager typeMgr; //null¿?
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || value.isEmpty()) {
return null;
}
try {
return typeMgr.findById(Integer.parseInt(value));
} catch(Exception e){
throw new ConverterException(new FacesMessage(value + " string is not a valid WorkType"));
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null) {
return null;
}
if (value instanceof WorkType) {
return ((WorkType)value).getId().toString();
} else {
throw new ConverterException(new FacesMessage(value + " object is not a valid WorkType"));
}
}
}
pom.xml dependencies
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>10.0.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>