Having recently upgraded to JSF 2.3
from 2.2
, I noticed that @ManagedBean
was deprecated, and after some research found that I should be using CDI-2.0
managed beans and the @Named
annotation.
I also migrated @javax.faces.bean.SessionScoped
to @javax.enterprise.context.SessionScoped
.
However i noticed that my beans are created on the server's startup!
I login with an user 'X' and i change an attribute in my bean. after that i login with another browser and i expect to find null in my attribute but i have found the last update by the user 'X' in the other browser.
I'm using myFaces 2.3, omnifaces 3.1, i also installed CDI in my tomcat. i have referenced to some blogs and some responses stackoverflow like :
http://balusc.omnifaces.org/2013/10/how-to-install-cdi-in-tomcat.html
Migrate JSF managed beans to CDI managed beans
Here are my principal files :
beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
pom.xml:
.....
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primefaces.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>${primefaces.all.themes}</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.omnifaces/omnifaces -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-impl -->
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.3.1</version>
</dependency>
<!-- Oracle jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
.....
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-faces</artifactId>
<version>2.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
Am i doing something wrong?
@javax.enterprise.context.SessionScoped
to@javax.faces.bean.SessionScoped
" -> you should be going the other way around. CDI version isjavax.entrerprise.context.SessionScoped
so that's the one you want to be using. – Siliarus