I want to migrate my JSF Application from ManagedBean to CDI Beans.
First of all I have done a simple test to see if CDI are working, but they don't. Here my example, using Wildfly 10 and myfaces 2.2
beans.xml in .\WEB-INF
<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_1_1.xsd"
bean-discovery-mode="all">
</beans>
xhtml page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>
test
</title>
</h:head>
<h:body>
<h:outputText value="#{CDITest.hello}"/>
<h:outputText value="test"/>
</h:body>
</html>
The backing Bean
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import java.io.Serializable;
@Named("CDITest")
@SessionScoped
public class CDITest implements Serializable{
public String getHello(){
return "Hello";
}
}
The output
test
No error message (!) and no call to CDITest.getHello() method. What I'm missing?
Upgrading to myfaces-2.3.6 (jsf 2.3) on Wildfly 19.0.0 solved the issue. Note that you need a @FacesConfig class as suggested by @Cristyan.
Note also that using Mojarra the issue didn't happen and the Bean worked as expected (for both Widlfly 10 and Widlfly 19).