我刚开始使用JSF并尝试一些示例实现。 我得到了以下Bean,web.xml和index.xhtml文件:
HelloBean.java:
package jsflearning;
import javax.inject.Named;
import javax.enterprise.context.*;
@Named(value= "myHelloBean")
@RequestScoped
public class HelloBean {
private String name = "dear reader";
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd">
<display-name>JSFLearning</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<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>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
的index.xhtml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>Simplest JSF Page</title>
</head>
<body>
<div align="center">
<br />
<h:form>
<h:inputText value="#{myHelloBean.name}"/>
</h:form>
<br />
Hello to you. #{myHelloBean.name} !
</div>
</body>
</html>
#{myHelloBean.name}
表达式已正确执行,但未解释<h:form>
标记且未显示编辑框。无法找到此问题的解决方案。
提前谢谢!
答案 0 :(得分:5)
仅在JSF 2.2之后才支持http://xmlns.jcp.org/jsf/*
XML命名空间。您的问题症状表明您仍在使用JSF 2.0或2.1。
你有两个选择:
将JSF库升级到JSF 2.2兼容版本。
将XML命名空间降级为兼容JSF 2.0 / 2.1 http://java.sun.com/jsf/*
。