0

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?

otisonoza
  • 1,324
  • 2
  • 13
  • 29
  • I don't see any obvious error, try with mvn package and then deploy the war manually to check if the problem is not eclipse. – nomoa Oct 30 '14 at 14:38
  • anything in the faces-config? It may be a mixup of annotations: http://stackoverflow.com/questions/4347374/backing-beans-managedbean-or-cdi-beans-named - or some missing bean resolver in faces-config? – wemu Oct 30 '14 at 15:54
  • 1
    Do you see any errors in console when opening a page? – n1k1ch Oct 30 '14 at 16:03
  • Is that beans.xml truly empty or does it contain ? And did you check what is actually deployed to the server? Your project may be 100% correct but if the deployment configuration is then wrong it still won't work. – Gimby Oct 30 '14 at 16:10
  • A beans.xml is not needed for this to work. You should add your web.xml to the question. – unwichtich Oct 30 '14 at 21:07
  • 1
    The beans.xml is the trigger file to get the CDI implementation to scan for beans in that module. If you don't add the beans.xml in the proper place (WEB-INF for web modules, META-INF for jar modules), no beans will be registered. – Gimby Oct 30 '14 at 22:35
  • I tried Java 8 with GF 4 resulting in some strange behavior (especially on list sorting), maybe it's related. Try to switch back to 7: compile your war and run GF with java 7 **binaries**, using java 8 with lower compiler level could not work. – Michele Mariotti Oct 31 '14 at 09:16
  • You should use glassfish 4.1 with java-8. Not sure if it solves your problem.. – Aksel Willgert Nov 04 '14 at 15:19

0 Answers0