提交表单后,很少有组件不会在 JSF 的 primefaces 中呈现
Few components are not rendering in primefaces in JSF, after submitting the form
我正在尝试使用 primefaces。当我试图在我的 eclipse IDE 中单独 运行 一个 xhtml 页面时,我的 "index.xhtml" 中包含的所有 primeface 元素工作正常,但是当我更新我的 "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>
尝试:
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
index.xhtml 页面应该使用 Faces-Servlet。
我终于解决了这个问题,实际上第一次可以完美加载表单,当我第二次提交值并尝试重新提交另一条记录时,很少有元素没有加载,
我第一次意识到问题出在primefaces上,但实际问题是,当通过setter初始化表单值并提交给后端时,它们实际上并没有被清除submission ,因此通过 getter 方法再次将过去记录的所有值重新加载到表单中。该表单包含素面日期元素,因为它们试图用以前的记录加载日期元素,这会给我一个错误,并且由于日期元素的错误而无法加载元素。
我所做的解决方案是在表单值提交到后端数据库后清除它们。
我正在尝试使用 primefaces。当我试图在我的 eclipse IDE 中单独 运行 一个 xhtml 页面时,我的 "index.xhtml" 中包含的所有 primeface 元素工作正常,但是当我更新我的 "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>
尝试:
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
index.xhtml 页面应该使用 Faces-Servlet。
我终于解决了这个问题,实际上第一次可以完美加载表单,当我第二次提交值并尝试重新提交另一条记录时,很少有元素没有加载,
我第一次意识到问题出在primefaces上,但实际问题是,当通过setter初始化表单值并提交给后端时,它们实际上并没有被清除submission ,因此通过 getter 方法再次将过去记录的所有值重新加载到表单中。该表单包含素面日期元素,因为它们试图用以前的记录加载日期元素,这会给我一个错误,并且由于日期元素的错误而无法加载元素。
我所做的解决方案是在表单值提交到后端数据库后清除它们。