Problem with JSF2 + CDI + Tomcat

Asked

Viewed 231 times

-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.

1 answer

1


You are only using the cdi api. You need the implementation as well, since Tomcat does not implement cdi.

<dependency>
    <groupId>org.jboss.weld.servlet</groupId>
    <artifactId>weld-servlet</artifactId>
    <version>2.4.8.Final</version>
</dependency>
  • Indeed, the implementation was lacking. Actually I tried several Uto and put this dependency in some moments of the test here, only then the server would stop going up and I would remove. I found that it does not rise by incompatibility of Spring Data with CDI. But there is another story. Thanks.

  • Beauty! If you can mark as solved to close the post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.