Make a h:inputText required only when the checkbox

2020-07-22 04:14发布

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条回答
家丑人穷心不美
2楼-- · 2020-07-22 04:53

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>
查看更多
登录 后发表回答