How to get check status from JSF component

I want to set a special error class for a div block in my custom component for JSF. I want to set errorClass to "error" if this field has not passed 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> 
+4
source share
1 answer

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 will not work in your div , as it is not a jsf component. You can 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> 
+4
source

All Articles