如何从JSF组件获取验证状态 [英] How to get validation status from JSF component
本文介绍了如何从JSF组件获取验证状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置一个特殊的错误类以将div块放入我的JSF自定义组件中.如果此字段通过验证失败,我想将errorClass设置为"error".
I want set a special error class to div block into my custom component for JSF. I want set errorClass to "error" if this field failed the validation.
<c:if test="${?????}">
<c:set var="errorClass" value="error" />
</c:if>
<div class="input ${errorClass}">
<label for="#{rich:clientId('input')}:input">#{cc.attrs.label}</label>
<h:inputText id="input" value="#{cc.attrs.value}"
<cc:insertChildren />
</h:inputText>
</div>
推荐答案
您可以在inputText的style或styleClass属性内使用component.valid
:
You can use component.valid
inside the style or styleClass attribute of your inputText:
<h:inputText value="#{cc.attrs.value}"
styleClass="#{component.valid ? '' : 'error'}" />
但是,这在您的div
中不起作用,因为它不是jsf组件.您可以尝试组件绑定(从理论上讲,未经测试):
However, this won't work in your div
since it is no jsf component. You could try component binding (from theory, not tested):
<div class="#{myComponent.valid ? '' : 'error'}">
<h:inputText id="input" value="#{cc.attrs.value}" binding="#{myComponent}">
<cc:insertChildren />
</h:inputText>
</div>
这篇关于如何从JSF组件获取验证状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文