我从这个 Primefaces http://blog.primefaces.org/?p=1512 关于简单密码验证的博客中复制了确切的代码
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{registerMB.password}"
feedback="false" match="pwd2" label="Password 1" required="true" />
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{registerMB.password}"
feedback="false" label="Password 2" required="true" />
<f:facet name="footer">
<p:commandButton value="Register" action="/pages/public/login" />
<p:commandButton value="Cancel" immediate="true"
action="/pages/public/login" />
</f:facet>
验证有效,但我只能得到验证错误。永远不会显示密码 1 应与密码 2 匹配的消息。还有这个配置吗?
我下载了 Primefaces 3.4.1
尝试添加以下内容
validatorMessage 属性 id="pwd2":
<p:password id="pwd2" value="#{registerMB.password}"
feedback="false" label="Password 2" required="true"
validatorMessage="password 1 should match password 2"/>
添加 p:message 标签以在 h:form 标签下方显示错误
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
添加
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
就像 int Primefaecs 密码展示
<h:form id="form">
<p:panel header="Match Mode">
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
<h:panelGrid columns="2" id="matchGrid">
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{passwordBean.password5}" match="pwd2" label="Password 1" required="true"/>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{passwordBean.password5}" label="Password 2" required="true"/>
</h:panelGrid>
<p:commandButton id="saveButton" update="matchGrid" value="Save" />
</p:panel>
</h:form>
您可以使用命名空间 jsf/core 中的元素命名属性 xmlns:f="http://xmlns.jcp.org/jsf/core"
<div class="mb-3">
<h:outputLabel for="passwordInput" value="Password" styleClass="label"/>
<h:inputSecret id="passwordInput" value="#{auth.userRegistration.password}" required="true"
requiredMessage="Password is required" styleClass="form-control" maxlength="30">
<f:validator validatorId="passwordValidator" />
<f:attribute name="password2" value="#{password2}"/>
</h:inputSecret>
<h:message for="passwordInput" styleClass="error"/>
</div>
<div class="mb-3">
<h:outputLabel for="passwordInput2" value="Confirm Password" styleClass="label"/>
<h:inputSecret id="passwordInput2" binding="#{password2}" required="true" maxlength="30"
requiredMessage="Password are not matched" styleClass="form-control"/>
<h:message for="passwordInput2" styleClass="error"/>
</div>