Using regex with p:keyFilter

前端 未结 1 432
轻奢々
轻奢々 2020-12-06 22:56

I have an p:inputMask with a p:keyFilter to match HH:MM as following:



        
相关标签:
1条回答
  • 2020-12-06 23:52

    p:keyFilter versus f:validateRegex

    p:keyFilter is used to filter characters (on each key stroke), it does not allow you to validate an expression (on the complete inputted value). If you want to validate if your input matches a regular expression use f:validateRegex.

    So, in your case:

    <p:inputMask id="heureDebutPlanningSalleAppareil"
                 value="#{beanFormPlanningSalleAppareil.planningSalleAppareil.heureDebut}"
                 required="true" maxlength="4" mask="99:99"
                 requiredMessage="Heure de début : vous devez indiquer une valeur.">
        <f:validateRegex pattern="([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]"/>
    </p:inputMask>
    

    You could ajaxify it to show a message on change:

    <p:inputMask id="heureDebutPlanningSalleAppareil"
                 value="#{beanFormPlanningSalleAppareil.planningSalleAppareil.heureDebut}"
                 required="true" maxlength="4" mask="99:99"
                 requiredMessage="Heure de début : vous devez indiquer une valeur."
                 validatorMessage="Your message">
        <f:validateRegex pattern="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$"/>
        <p:ajax process="@this" update="heureDebutPlanningSalleAppareilMsg"/>
    </p:inputMask>
    <p:message for="heureDebutPlanningSalleAppareil" 
               id="heureDebutPlanningSalleAppareilMsg"/>
    

    For something completely different

    You could have a look at pe:timePicker. This component is made for what you are trying to "hack" here.

    0 讨论(0)
提交回复
热议问题