How to change css class for the inputfield and label when validation fails?

后端 未结 2 917
遇见更好的自我
遇见更好的自我 2020-12-06 15:35

Suppose I have a username to validate, in this case I need to show username outputText and username inputText field in red color when validation fails along with error messa

2条回答
  •  無奈伤痛
    2020-12-06 16:12

    Bind the input component to the view via binding attribute. It'll become available as an UIInput component reference in EL, so that you can use UIInput#isValid() in styleClass attribute.

    
    
    
    

    (note that I fixed your label to be a real label; also note that you don't need to create some bean property at all as suggested by the answer of cubbuk)

    Yes, this may produce quite some non-DRY boilerplate code in the view. You can abstract this away with a phase listener or a system event listener. You can also use OmniFaces component which does all the job transparently. See also the live demo.

提交回复
热议问题