Styling input component after validation failed

后端 未结 2 1400
遇见更好的自我
遇见更好的自我 2020-12-20 03:23

How can I style a component after validation failed?

I have the following textfield:



        
2条回答
  •  無奈伤痛
    2020-12-20 03:37

    Your concrete problem is caused because you didn't update the input component on complete of the ajax request. You're only updating the growl component. So the changes to the input component are never reflected into the client side.

    I suggest to just update the entire form as it might contain other input components which also needs to be highlighted:

    
    

    By the way, the @ListenersFor (and @ListenerFor) is misplaced here. It doesn't work that way and they're plain ignored. Get rid of them. See also How to register a (Component)SystemEventListener for all UIInputs.


    Unrelated to the concrete problem, this SystemEventListener approach to highlight failed input components is flawed. It will fail when the input component is inside an iterating component such as or . It would highlight the input component in all rows even when only one of them has failed.

    Better go for a client side approach instead. The JSF utility library OmniFaces offers the component for exactly this purpose. See also the tag documentation, the showcase example and the source code.

提交回复
热议问题