Conditional style in JSF when validation has failed in general

后端 未结 1 1560
再見小時候
再見小時候 2020-12-11 16:17

i have h:messages to display error messages, and there\'s a component that i want its style to change in case of validation error occurs (if any component has a validation e

相关标签:
1条回答
  • 2020-12-11 16:33

    You can use FacesContext#isValidationFailed() to check if validation has failed in general.

    <h:outputText ... styleClass="#{facesContext.validationFailed ? 'fail' : 'success'}" />
    

    Alternatively, you can use FacesContext#getMessageList() to check if there are any faces messages. This does not necessarily indicate a general validation failure, there can namely also be global/success messages which are been added in action method.

    <h:outputText ... styleClass="#{not empty facesContext.messageList ? 'hasmessage' : 'nomessage'}" />
    
    0 讨论(0)
提交回复
热议问题