【发布时间】:2014-06-11 13:19:31
【问题描述】:
我有一个简单的 maven jsf2.2 项目,我使用 maven jetty 插件执行。
我有以下 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();
}
}
这是视图:
<?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>
如果我启动 jetty 并打开 index.xhtml,它会被渲染,但不会显示 varFromBeanOne 值,并且我的 bean 的 init 函数不会在我启动 jetty 的控制台中打印出任何内容。所以我想它根本没有被调用。
如果我将 @Named 更改为 @ManagedBean 一切正常。
这是我的 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>
我不知道为什么会这样。但我需要 JSF2.2 用于 CDI1.2。提示为什么它不工作或链接到工作的 maven - 没有 @ManagedBean 的 jsf2.2 示例会很棒。
【问题讨论】:
标签: java maven annotations jetty jsf-2.2