primefaces 中的密码匹配消息

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

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

jsf-2 primefaces
3个回答
3
投票

尝试添加以下内容

    p:password 标签内的
  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"/>
    
  2. 添加 p:message 标签以在 h:form 标签下方显示错误

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

2
投票

添加

<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>  

0
投票

您可以使用命名空间 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>
© www.soinside.com 2019 - 2024. All rights reserved.