5

I have an input text that is mapped to a Long property.

private Long length;

<h:inputText value="#{bean.length}" />

When I enter non-digits in that input text, I get the following conversion error:

myForm:myField: 'someText' must be a number consisting of one or more digits.

I was wondering how to customize this message to:

length must be a number greater than zero.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
fresh_dev
  • 6,694
  • 23
  • 67
  • 95

1 Answers1

9

Either use the input component's converterMessage attribute:

<h:inputText converterMessage="length must be a number greater than zero" />

(and don't forget to use <f:validateLongRange> to prevent users being able to enter negative values and supply a validatorMessage!)

Or create a properties file in the classpath which overrides the default message of the builtin JSF LongConverter:

javax.faces.converter.LongConverter.LONG = length must be a number greater than zero

and is been registered as message bundle in faces-config.xml:

<application>
    <message-bundle>com.example.CustomMessages</message-bundle>
</application>

The above example assumes that the file name is CustomMessages.properties and is been placed in com.example package. You can name and place it wherever you want.

You can find an overview of all message keys like javax.faces.converter.LongConverter.LONG and their default values in chapter 2.5.2.4 of the JSF specification which is also copypasted in this answer.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Does EL work here? like - converterMessage="#{messages.errorMessage}" This is for JSF 1.2. I tried by giving plain text. It works fine. But with EL, it does not work. Any changes to be done to support EL? – user001 Jul 01 '19 at 16:34