How to get validation status from JSF component
java, jsf, jsf-2, validation
Solution
You can use `component.valid` inside the style or styleClass attribute of your inputText:
<h:inputText value="#{cc.attrs.value}"
styleClass="#{component.valid ? '' : 'error'}" />
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>
Problem
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> ```