0

我从这个 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

4

2 回答 2

3

尝试添加以下内容

  1. p:password 标签 id="pwd2" 内的 validatorMessage 属性:

                <p:password id="pwd2" value="#{registerMB.password}"
                    feedback="false" label="Password 2" required="true"     
                   validatorMessage="password 1 should match password 2"/>
    
  2. 添加 p:message 标签以在 h:form 标签下方显示错误

     <p:messages id="messages" showDetail="true" autoUpdate="true"/> 
    
于 2016-08-30T07:52:12.320 回答
2

添加<p:messages id="messages" showDetail="true" autoUpdate="true"/>

就像 int Primefaecs Password Showcase

<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>  
于 2012-11-13T10:27:17.803 回答