Bhavesh
Bhavesh

Reputation: 4677

Digit only text field in JSF

How to allow a text field to permit only digits in JSF? I searched about it on Google a lot but could not find the solution in JSF.

Upvotes: 1

Views: 1673

Answers (1)

BalusC
BalusC

Reputation: 1109745

Just bind it to an Integer property.

E.g.

private Integer number;

with

<h:inputText id="number" value="#{bean.number}" />
<h:message for="number" />

It'll show a conversion error when you submit non-digits.

Upvotes: 5

Related Questions