JSF Primefaces 验证不起作用

问题描述 投票:0回答:2

单击提交按钮后,它没有点击我的托管 bean,但也没有显示验证消息。我觉得这很简单,不知道为什么它不起作用。

<h:form prependId="false">
  <table class="contactForm">
    <tr>
      <td>Name: </td>
      <td><p:inputText size="20" id="name" value="#{contactManagedBean.name}" required="true" requiredMessage="Name is required" /></td>
      <td><p:message for="name" /></td>
    </tr>
    <tr>
      <td>Email: </td>
      <td><p:inputText size="20" id="email" value="#{contactManagedBean.email}" required="true" requiredMessage="Email is required" /></td>
      <td><p:message for="email" /></td>
    </tr>
    <tr>
      <td>Phone (###-###-####) (Optional): </td>
      <td><p:inputText size="20" id="phone" maxlength="12" value="#{contactManagedBean.phone}"/></td>
      <td><p:message for="phone" /></td>
    </tr>
    <tr>
      <td>Comments: </td>
      <td><p:inputTextarea rows="5" cols="30" id="comments" value="#{contactManagedBean.comments}" required="true" requiredMessage="Please enter some comments"></p:inputTextarea></td>
      <td><p:message for="comments" /></td>
    </tr>
    <tr>
      <td colspan="3" style="text-align: center;"><p:commandButton value="Submit" actionListener="#{contactManagedBean.submitComment()}" /></td>
    </tr>
  </table>
</h:form>
validation jsf primefaces
2个回答
7
投票

将 id 添加到 h:form 并将更新属性添加到按钮。 例如:

<h:form id="form">
...
<p:commandButton value="Submit" update="form" actionListener="#{contactManagedBean.submitComment()}" />
</h:form>

0
投票

还要确保在你的 commandButton 上你永远不会有 process="@this"

© www.soinside.com 2019 - 2024. All rights reserved.