108
PrimeFaces InputMask
It is a special type of input box which forces user to enter formatted input. We can create it by using <p:inputMask> component. It takes input in a certain pattern. It is useful when we want formated user input. It has various attributes that are listed below.
InputMask Attributes
Attribute | Default Value | Return type | Description |
---|---|---|---|
id | null | String | It is an unique identifier of the component. |
rendered | true | Boolean | It is used to specify the rendering of the component. |
mask | null | Object | It is used to set mask template. |
slotChar | null | String | It is a placeHolder in mask template. |
value | null | object | It is used to set value of the component. |
required | false | Boolean | It is used to make component as required. |
maxlength | null | Integer | It is used to set maximum number of characters that may be entered in this field. |
onblur | null | String | It is used to call script when input element loses focus. |
onselect | null | String | It is used to execute script when text within input element is selected by user. |
placeholder | null | String | It is used to specify a short hint. |
readonly | false | Boolean | It is used to set component readonly. |
size | null | Integer | It is used to set number of characters used to determine the width of the input element. |
autoClear | true | Boolean | It is used to clear the field on blur when incomplete input is entered. |
Example
Here, in the following example, we are implementing <p:inpuMask> component. This example contains the following files.
JSF File
// inputMask.xhtml
ManagedBean
// InputMask.java
Output:
Next TopicPrimeFaces SelectOneListbox