-1
Personal talk,
I’m working with JSF and I’m here.
I have a simple project for now, with a page with a form that has an Enum attribute in it, IE, when the page is loaded has a selectItems there that should be loaded from Enum.
Using @Managedbean and the JSF scope it works normally. But when I try to migrate to CDI, Enum ceases to be loaded.
I have tested trying to write a simple attribute on the screen and neither will.
From what I saw, it should be simple, but I’ve followed several tutorials and failed miserably. Of course it must be silly of me, but I can’t see what it is. In the console no error msg appears and the page loads normally, only it does not bring anything from Managed Bean.
I already wrote down named in bean, Enum and nothing. And then, what’s the catch?
POM.xml
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>${jsf-api.version}</version>
</dependency>
<!-- Servelet -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>${javaee-web-api.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.17</version>
</dependency>
//Outras dependências (JPA, Hibernate, Wildfly)
WEB-INF/Beans.xml
<?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_1_1.xsd"
version="2.0" bean-discovery-mode="all">
</beans>
WEB-INF/xml context.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/</Context>
MB
@Named //javax.inject.Named
@RequestScoped //javax.enterprise.context.RequestScoped
public class CadastroQuestaoMB implements Serializable
{
private static final long serialVersionUID = 1L;
@Inject
Questao questao;
...
Unfortunately I don’t know much about CDI, but in this project (https://github.com/algaworks/curso-javaee-primefaces) I know that they use, try to take a look and see if it clarifies their doubt.
– Adriano Gomes