primefaces中的密码匹配消息

时间:2012-11-13 09:40:52

标签: jsf-2 primefaces

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

2 个答案:

答案 0 :(得分:3)

尝试添加以下内容

  1. 在p:password tag 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"/> 
    

答案 1 :(得分: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>