How to customize JSF conversion message 'must be a number consisting of one or more digits'?

后端 未结 1 909
暗喜
暗喜 2020-12-19 10:58

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

private Long length;



        
1条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 11:05

    Either use the input component's converterMessage attribute:

    
    

    (and don't forget to use 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:

    
        com.example.CustomMessages
    
    

    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.

    0 讨论(0)
提交回复
热议问题