我有一个数据表,其中的行包含一些必需的输入文本字段。每行还有一个称为删除的复选框。我希望只有在选中复选框时才具有 required="true"
。我怎样才能做到这一点?
最佳答案
只需让输入的 required
属性检查复选框的值即可。
这是一个启动示例:
<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>
关于jsf - 做一个 h :inputText required only when the checkbox is selected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5182106/