Make a h:inputText required only when the checkbox is selected

不打扰是莪最后的温柔 提交于 2020-01-01 11:59:07

问题


I have a datatable with rows containing some input text fields that are required. Each row also has a check box called delete. I want to have the required = "true" only when the check box is selected. How can I achieve this?


回答1:


Just let the input's required attribute check the checkbox's value.

Here's a kickoff example:

<h:form>
    <h:dataTable value="#{bean.list}" var="item">
        <h:column><h:selectBooleanCheckbox binding="#{checkbox}" /></h:column>
        <h:column><h:inputText id="input" value="#{item.value}" required="#{checkbox.value == 'true'}" /></h:column>
        <h:column><h:message for="input" /></h:column>
    </h:dataTable>
    <h:commandButton value="submit" action="#{bean.submit}" />
</h:form>


来源:https://stackoverflow.com/questions/5182106/make-a-hinputtext-required-only-when-the-checkbox-is-selected

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