Mark Estrada
Mark Estrada

Reputation: 9201

Password matching message in primefaces

I copied the exact code from this Primefaces http://blog.primefaces.org/?p=1512 blog about easy password validation

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

Validation works but I am only able to get the Validation Error. The message Password 1 should match Password 2 is never displayed. Is there anymore configuration for this?

I have Primefaces 3.4.1 downloaded

Upvotes: 0

Views: 11643

Answers (3)

Soufiane-Chajjaoui
Soufiane-Chajjaoui

Reputation: 51

You can use element named attribute from namespace 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>

Upvotes: 0

Hodeifa Baswel
Hodeifa Baswel

Reputation: 177

Try to add the following

  1. validatorMessage atribute inside p:password tag id="pwd2":

                <p:password id="pwd2" value="#{registerMB.password}"
                    feedback="false" label="Password 2" required="true"     
                   validatorMessage="password 1 should match password 2"/>
    
  2. add p:message tag to show the error below the h:form tag

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

Upvotes: 3

Daniel
Daniel

Reputation: 37061

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

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

Upvotes: 2

Related Questions