How to get validation status from JSF component

北城以北 提交于 2019-12-23 12:45:57

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/11559460/how-to-get-validation-status-from-jsf-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!