根据另一个输入组件的值来禁用/启用JSF输入组件 [英] Disable/enable a JSF input component depending on value of another input component

查看:103
本文介绍了根据另一个输入组件的值来禁用/启用JSF输入组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个单选按钮:

<h:selectOneRadio value="#{bean.choice}">
    <f:selectItem itemValue="yes" itemLabel="YES" />
    <f:selectItem itemValue="no" itemLabel="NO" />
</h:selectOneRadio>

<p:calendar value="#{bean.date}" />

如果选择否"按钮,则日历的文本输入字段应被禁用(变灰).我该怎么办?

If the "no" button is selected, the text input field of the calendar should be disabled (greyed out). How can I do this?

推荐答案

只需让目标输入组件的disabled属性检查源输入的值,然后在源组件中使用<f:ajax>来更新目标组件.这将导致重新评估disabled属性.不需要值更改侦听器或其他属性.

Just let the target input component's disabled attribute check the value of the source input and use <f:ajax> in the source component to update the target component. It will cause the disabled attribute to be re-evaluated. No need for a value change listener nor an additional property.

<h:selectOneRadio value="#{bean.choice}">
    <f:selectItem itemValue="yes" itemLabel="YES" />
    <f:selectItem itemValue="no" itemLabel="NO" />
    <f:ajax render="calendar" />
</h:selectOneRadio>

<p:calendar id="calendar" value="#{bean.date}" disabled="#{bean.choice eq 'no'}" />

另请参见:

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