Reputation: 765
i have a simple maven jsf2.2 project, which i execute with the the maven jetty plugin.
i have the following bean:
package de.swp14i;
import javax.inject.Named;
//import javax.faces.bean.ManagedBean;
@Named
//@ManagedBean
public class BeanOne {
private String varFromBeanOne = "BeanOne";
public String getVarFromBeanOne() {
return this.varFromBeanOne;
}
public void init() {
System.out.println();
}
}
And the this is the View:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html" >
<h:head>
<title>JSF 2.2 HTML5</title>
</h:head>
<h:body>
<h1>Blub</h1>
<h:outputText id="beanOne" value="#{beanOne.varFromBeanOne}"></h:outputText>
</h:body>
</html>
If i start jetty and open index.xhtml it is rendered, but the varFromBeanOne value is not displayed and the init function of my bean does not print out anything in the console where i started jetty. So i guess it is not called at all.
If i change @Named to @ManagedBean everything works fine.
here is my 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">
<!-- pom.xml specification version -->
<modelVersion>4.0.0</modelVersion>
<!-- project settings -->
<groupId>de.swp14i</groupId>
<artifactId>example</artifactId>
<version>0.1</version>
<name>example</name>
<packaging>war</packaging>
<properties>
<encoding>UTF-8</encoding>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-war-plugin.version>2.4</maven-war-plugin.version>
<jetty-maven-plugin.version>9.2.0.M1</jetty-maven-plugin.version>
</properties>
<!-- project module dependencies -->
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<!-- project maven plugins -->
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
I have no clue why this happens. But i need JSF2.2 for CDI1.2. A hint why its not working or a link to a working maven - jsf2.2 example without @ManagedBean would be wonderful.
Upvotes: 0
Views: 1229
Reputation: 509
You can try to clean the project and rerun it. Sometimes code changes are not updated correctly by ide. Add a cdi scope like @ViewScoped (import javax.faces.view.ViewScoped;) and try again.
Update : I see that you are using jetty as web container. I search for jetty cdi and found that jetty is not supporting CDI by default. Weld can be used to add support for CDI :
http://www.eclipse.org/jetty/documentation/current/framework-weld.html
Deploying a war to Jetty with CDI
Upvotes: 1