一般情况下,验证失败时,JSF中的条件样式 [英] Conditional style in JSF when validation has failed in general

查看:97
本文介绍了一般情况下,验证失败时,JSF中的条件样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有h:messages来显示错误消息,并且有一个组件我希望它的样式在发生验证错误的情况下发生变化(如果任何组件出现验证错误或呈现了任何验证消息,请更改此样式特定组件).

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 error or any validation message is rendered then change the style of this specific component).

我知道如果组件存在验证错误,则更改样式的方法: JSF:检查<是否存在的更好方法; h:message for ="id"/>

i know about the way to change the style if the component has validation errors: JSF : Better way to check for existence of <h:message for="id"/>

但是我想要一个更通用的方法,如果表单中的任何组件无效,或者换句话说,呈现任何验证消息,则更改样式.

but i want a more general way, to change style if any component in the form is not valid, or in other words any validation message is rendered.

请告知如何完成该操作.

please advise how to accomplish that.

推荐答案

您可以使用

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

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

或者,您可以使用 FacesContext#getMessageList() 检查是否有面部消息.这并不一定表示一般的验证失败,也可能是在动作方法中添加了全局/成功消息.

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'}" />

这篇关于一般情况下,验证失败时,JSF中的条件样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆