Sidaoui Majdi
Sidaoui Majdi

Reputation: 419

Specifying the min-length of p:password

I'm a beginner with PrimeFaces and I wont to save a form that contains an input password, but when i try to save a password with length 2 or 3 characters nothing happened. It's likely that the button doesn't work. This is my example

<h:form id="mainForm">
    <p:messages autoUpdate="true"/>

    <p:panel header="Paramétrage des adresses">
        <h:panelGrid id="createGrid"
                     columns="2"
                     cellspacing="100"
                     cellpadding="25">

            <h:outputLabel for="pwd1" value="Mot de passe : *"/>

            <p:password id="pwd1" value="#{adress.currentAdress.motDePasse}"
                        match="pwd2"
                        label="Mot de passe"
                        required="true"
                        maxlength="100">

                <p:message for="pwd1"/>
            </p:password>

            <h:outputLabel for="pwd2" value="Confirmation Mot de passe : *"/>

            <p:password id="pwd2"
                        value="#{adress.currentAdress.motDePasse}"
                        label="confirmation" required="true"/>
        </h:panelGrid>

        <p:commandButton id="saveAdress"
                         type="button" value="valider"
                         action="#{adress.save}"
                         update="createGrid dataTable"/>
    </p:panel>
</h:form>

Upvotes: 2

Views: 8175

Answers (1)

Scorpion
Scorpion

Reputation: 587

you can use <f:validateLength> tag to validate the length of your UIInput , your <p:password> will be like this

 <p:password id="pwd1" value="#{adress.currentAdress.motDePasse}" match="pwd2" 
        label="Mot de passe" required="true" maxlength="100">
     <f:validateLength minimum="2" ></f:validateLength>
 </p:password>
 <p:message for="pwd1"/>

This will fire a validation error whenever you submit a password less than 2 characters. For additional information look here.

Upvotes: 9

Related Questions