1

I'd like to show a custom message when the user enters a non-number.

For that, I specified validatorMessage attribute:

<h:inputText value="#{bean.commission}" required="true"
    requiredMessage="Please enter a value"
    validatorMessage="Please enter a number" />

The required message appears correctly on empty input, but the validator message doesn't appear on non-number input. Instead, it shows the default message that the input value is not a number.

How is this caused and how can I solve it?

4

1 回答 1

1

您遇到了转换错误,而不是验证错误。

改为使用converterMessage

<h:inputText value="#{bean.commission}" required="true"
    requiredMessage="Please enter a value"
    converterMessage="Please enter a number" />

validatorMessage仅用于通过属性指定的验证器以及validator通过嵌套<f:validator><f:validateXxx>标签指定的验证器。

converterMessage用于通过converter属性指定的转换器和通过嵌套和<f:converter>标签<f:convertXxx>指定的转换器,用于特定类的自动注册转换器,例如/ typedIntegerConverter的情况。intIntegervalue

也可以看看:

于 2015-03-04T18:22:37.810 回答