The <f:validateRegex>
is intented to be used on String
properties only. But you've there an int
property for which JSF would already convert the submitted String
value to Integer
before validation. This explains the exception you're seeing.
But as you're already using an int
property, you would already get a conversion error when you enter non-digits. The conversion error message is by the way configureable by converterMessage
attribute. So you don't need to use regex at all.
As to the concrete functional requirement, you seem to want to validate the min/max length. For that you should be using <f:validateLength>
instead. Use this in combination with the maxlength
attribute so that the enduser won't be able to enter more than 6 characters anyway.
<h:inputText value="#{bean.number}" maxlength="6">
<f:validateLength minimum="6" maximum="6" />
</h:inputText>
You can configure the validation error message by the validatorMessage
by the way. So, all with all it could look like this:
<h:inputText value="#{bean.number}" maxlength="6"
converterMessage="Please enter digits only."
validatorMessage="Please enter 6 digits.">
<f:validateLength minimum="6" maximum="6" />
</h:inputText>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…