O'Reilly logo

PrimeFaces Cookbook - Second Edition by Oleg Varaksin, Mert Çalışkan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Formatted input with inputMask

inputMask minimizes the chances for the user to input incorrect data. It applies client-side validation with the provided masking template.

How to do it...

A basic example of an input mask for a phone number input would be as follows:

<p:inputMask value="#{inputMaskBean.phone}"
  mask="(999) 999-9999"/>

As can be seen with the mask (999) 999-9999, it is stated that only numbers can be input along with the parenthesis and dashed structure. The initial visual of the input will be as seen in the following screenshot:

How to do it...

The fields that are filled up with number 9 in the mask will be empty and the rest will be rendered with the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required