I created a simple Maven project in Eclipse.
My container is Glassfish 4.
First I added the following dependencies:
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maven_cinema</groupId>
<artifactId>maven_webapp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>maven_webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>maven_webapp</finalName>
</build>
</project>
Then I created an empty beans.xml in the WEB-INF folder.
Then in the project properties I changed the Java version to 1.8.
Then Dynamic Web Module to 3.1.
Then enabled JavaServerFaces 2.2. (I downloaded the Mojarra library.)
This is my model:
package model;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class LoginModel implements Serializable {
private static final long serialVersionUID = 1L;
private String name = "Maven";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
When I try to bind the property in a JSF page:
<body>
<h:outputText value="#{loginModel.name}" />
</body>
The body is empty.
But when I do something like:
<h:outputText value="abc" />
It works.
So it must be the CDI.
What do I have to configure?