【问题标题】:Few components are not rendering in primefaces in JSF, after submitting the form提交表单后,很少有组件不会在 JSF 中的 primefaces 中呈现
【发布时间】:2015-06-01 16:44:45
【问题描述】:

我正在尝试在 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>

【问题讨论】:

  • 先生。 BalusC,您标记为重复的问题与我问的问题不同。我检查了两次,看到这里我的问题是提交我的实际问题的表单后元素没有正确呈现。

标签: jsf jsf-2 primefaces


【解决方案1】:

我终于解决了这个问题,表单实际上第一次加载完美,当我提交值并尝试第二次重新提交另一条记录时,很少有元素没有加载,

我首先意识到问题出在primefaces,但实际问题是这样的,当表单值通过setter初始化并提交到后端时,它们实际上并没有在提交后被清除,所以所有的值过去的记录再次通过 getter 方法重新加载到表单中。表单包含素面日期元素,因为他们试图加载具有先前记录的日期元素,这给我一个错误,并且由于日期元素的错误而没有加载元素。

我所做的解决方案是在表单值提交到后端数据库后清除它们。

【讨论】:

    【解决方案2】:

    试试:

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

    index.xhtml 页面应该使用 Faces-Servlet。

    【讨论】:

    • 为什么元素没有一直渲染?因为当我第一次运行该元素时,当我第二次执行相同的代码时,我能够获取所有元素,我看到一些元素丢失了?这有什么具体原因吗?
    • 当我设计完整的表单时,代码适用于少数元素,它不会再次显示任何内容
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多