7

I just created a new maven project and Added a index controller. Then I used managedbean annotation. But I get this message The type ManagedBean is deprecated. So I tried for alternatives but I could not find any solutions. All the articles uses @ManageBean. So I think am missing something here.

My pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>asf.asdflksdfklj</groupId>
  <artifactId>Demo-App</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>Demo-App</name>

  <dependencies>
  <dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>5.3</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>
    <version>2.3.0-m06</version>
  </dependency>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.0-b01</version>
  </dependency>
  </dependencies>


  <build>
  <plugins>
  <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.4.0.M0</version>
  </plugin>
  </plugins>
  </build>


</project>  

and IndexController

package asf.asdflksdfklj.Controller;

import javax.faces.bean.ManagedBean;


@ManagedBean
public class IndexController {

    public String showHello(){
        return "hello world";
    }

}

Is it really ManagedBean deprecated? If so what should I use to make this code work?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452

1 Answers1

19

Managed beans are being deprecated and replaced with CDI beans. You will eventually have to upgrade to CDI, so might as well start now.

Instead of @ManagedBean, if you use @Named and put cdi-api-1.2.jar in your dependency, you should be good to go:

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;

@Named
@SessionScoped
public class IndexController implements Serializable {

}
CodeSlave
  • 341
  • 4
  • 17
koque
  • 1,182
  • 2
  • 15
  • 35