I have an InputText
component wired to a Bean property of int type.
However, I\'m forced to use NumberConverter
only
Even when I specify
Create a custom converter extending the default NumberConverter
wherein you check the string value before delegating to the NumberConverter
and then use it instead.
public class MyNumberConverter extends NumberConverter {
public MyNumberConverter() {
setIntegerOnly(true);
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if (submittedValue != null && !submittedValue.matches("[0-9]+")) {
throw new ConverterException("Please enter digits only");
}
return super.getAsObject(context, component, submittedValue);
}
}
<f:converter converterId="myNumberConverter" />