Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I migrated a Primefaces 6 application to JBoss EAP 7.4 and upgraded to Primefaces 10 and JSF2.2 to JSF2.3. After this migration, the @Inject we had in the FacesConverter is not being initialized and thus returning null. This question might be duplicate (
https://stackoverflow.com/a/47447140/1918516
), the proposed answers did not resolve my issue.
Below my current project structure.
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
</faces-config>
MyConverter.java
@FacesConverter(value = "MyConverter", managed = true)
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class MyConverter implements Converter {
@Inject
private MyBean myBean;
MyBean.java
@Stateless
@Named
public class MyBean{
Jsf23Activator.java
@ApplicationScoped
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class Jsf23Activator {
web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<param-name>javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I have not created a beans.xml as it is not required with newer versions as far as i know. Also when creating one, i got the common error:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408:
Unsatisfied dependencies for type MyDao with
qualifiers @Default
I got it work for the converters by injecting with CDI.current().select(MyBean.class).get();
but for me this is just a workaround
Another approach would be to make a @Named out of the MyConverter and use following in my jsf, but that would be ideal for JSF 2.2 not 2.3 :
<h:inputSomething ...>
<f:converter binding="#{myConverter}" />
</h:inputSomething>
–
The missing part of the implementation, was the beans.xml file which I intentionally did not use as starting from version 1.1 it is not mandatory, as mentioned in my question as well.
It looks that in order to inject inside a FacesConverter the creation of the following beans.xml file is needed as well.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all"
version="2.0">
</beans>
I use Jboss 7.4 EAP and my @Inject works fine inside my converters. Here is my example converter. Then again I DO have a beans.xml in my WEB-INF/ folder.
@FacesConverter(forClass = AnnulmentReason.class)
public class AnnulmentReasonConverter extends AbstractEntityConverter<AnnulmentReason, Long> {
/** ApplicationScoped cache */
@Inject
EntityCache<AnnulmentReason, Long> cache;
@Override
protected AnnulmentReason getObjectById(final Long id) {
final Map<Long, AnnulmentReason> map = cache.getMap();
final AnnulmentReason ar = map.get(id);
return ar;
@Override
protected Long getObjectId(final AnnulmentReason entity) {
return entity.getId();
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.