JSF托管bean不显示

时间:2017-09-10 15:48:45

标签: jsf el

我正在使用IntelliJ Ultimate免费试用版,Maven 3.5.0版,Tomcat 6.0.53版,我下载并解压缩的Java EE Web配置文件(这就是它所说的全部)。我开始了一个Maven项目。我的程序只打印标题“Test”而不是bean。

在home.xhtml中,我最初尝试输出:#{helloWorld.getMessage()}

这将是粉红色的,并带有一条消息:“JSF EL属于属性。”如果我跑,我收到一条崩溃信息:“遇到”“(”“(”“第1行,第24栏”

我将代码更改为您现在看到的内容。它运行但不访问bean,只打印标题“Test”。

请问任何想法?

home.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF Tutorial!</title>
</h:head>

<h:body>
<h1>Test </h1>
<h:outputText value="#{helloWorld.message}"/>

</h:body>
</html>

HelloWorld.java:

package com.tutorialspoint.test;

import javax.faces.bean.ManagedBean;

@ManagedBean(name = "helloWorld", eager = true)
public class HelloWorld {

public String message = "This is the string from class HelloWorld";

public HelloWorld() {
    System.out.println("HelloWorld started!");
}

public String getMessage() {
    return message;
}
}

的web.xml:

<?xml version = "1.0" encoding = "UTF-8"?>
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
     xmlns = "http://java.sun.com/xml/ns/javaee"
     xmlns:web = "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     id = "WebApp_ID" version="2.5">

<welcome-file-list>
<welcome-file>faces/home.xhtml</welcome-file>
</welcome-file-list>

<!--
 FacesServlet is main servlet responsible to handle all request.
 It acts as central controller.
 This servlet initializes the JSF components before the JSP is displayed.
-->

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

</web-app>

的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>com.tutorialspoint.test</groupId>
<artifactId>helloworld</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>helloworld 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>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.1.7</version>
</dependency>

<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.1.7</version>
</dependency>

</dependencies>

<build>
<finalName>helloworld</finalName>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.1</version>

    <configuration>
      <source>1.6</source>
      <target>1.6</target>
    </configuration>
  </plugin>


  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat6-maven-plugin</artifactId>
    <version>2.2</version>

    <configuration>
      <port>9999</port>
      <path>/</path>
    </configuration>
  </plugin>


</plugins>

</build>
</project>

0 个答案:

没有答案