我正在尝试使用primefaces。当我试图在我的eclipse IDE中单独运行一个xhtml页面时,所有的primeface元素都包含在我的" index.xhtml"工作正常,但当我更新我的" web.xml"设置" index.xhtml"作为一个主页和整个执行项目元素没有正确呈现我的代码编写如下。当我提交表格并希望再次重新提交另一个条目时,问题就出现了。
的index.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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"
xmlns:f="http://java.sun.com/jsf/core"`enter code here`
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Visitor Information</title>
</h:head>
<h:body>
<h1 align="center">Visitor information</h1>
<p:outputLabel>
Name:
</p:outputLabel><p:inputText />
form-Element 1
form-Element 2
form-Element 3
form-Date element 1
form-Data element 2
</h:body>
</html>
Web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>jsfwebapp</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<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>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
答案 0 :(得分:1)
我终于修复了问题,表单实际上是第一次完美加载,当我提交值并尝试重新提交另一条记录时,很少有元素没有加载,
我首先意识到问题出在Primefaces上,但实际问题是这样,当表单值通过setter初始化并提交给后端时,它们在提交后实际上并没有被清除,所以所有的值过去的记录再次通过getter方法重新加载到表单中。表单包含prime-face日期元素,因为他们试图加载带有前一条记录的date-element,这会导致错误,并且由于date-element的错误而没有加载元素。
我所做的解决方案是在将表单值提交到后端数据库后清除它们。
答案 1 :(得分:0)
尝试:
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
index.xhtml页面应该使用Faces-Servlet。