JSF validation. can this be simplified?

后端 未结 1 1428
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 19:42

I have a simple form with a bunch of fields. each of them is required, and each has a different name:

  • city
  • state

when the form is submi

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 20:10

    Either use requiredMessage attribute

    
    

    Or use label attribute and supply a custom required message template.

    
    

    with a CustomMessages.properties in the classpath which contains the custom message template

    javax.faces.component.UIInput.REQUIRED = {0} is required.
    

    The {0} will be substituted with the value of the label attribute. You can find an overview of all keys in the JSF specification (e.g. JSF 2.0 spec - chapter 2.5.2.4). Declare the message properties file in faces-config.xml as message-bundle:

    
        com.example.CustomMessages
    
    

    (assuming that it's in the package com.example, you can name it whatever you want)

    For more message template keys, check the JSF specification.

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