问题
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