根据另一个输入组件的值来禁用/启用JSF输入组件 [英] Disable/enable a JSF input component depending on value of another input component
本文介绍了根据另一个输入组件的值来禁用/启用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'}" />
另请参见:
- 了解PrimeFaces流程/更新和JSF f: Ajax执行/渲染属性
- 何时使用valueChangeListener或f:ajax监听器?
- Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
- When to use valueChangeListener or f:ajax listener?
See also:
这篇关于根据另一个输入组件的值来禁用/启用JSF输入组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文