仅在选中此复选框时才需要h:inputText [英] Make a h:inputText required only when the checkbox is selected

查看:93
本文介绍了仅在选中此复选框时才需要h:inputText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,其中的行包含一些必需的输入文本字段。每行还具有一个称为删除的复选框。我只想在选中复选框后才具有 required = true 。我该如何实现呢?

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?

推荐答案

只需让输入的必需属性选中复选框的值。

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

这里有一个启动示例:

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

这篇关于仅在选中此复选框时才需要h:inputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆