【问题标题】:Disable User Selection in <h:selectOneRadio>在 <h:selectOneRadio> 中禁用用户选择
【发布时间】:2011-11-21 17:59:49
【问题描述】:

我正在尝试禁用标签中的用户选择。

    <h:selectOneRadio id="wildcard"   value="#{NewService.isWildCard}" label="#{msg.org_IsWildCard}" readonly="true" layout="lineDirection">              
                                        <f:selectItem id="yes" itemLabel="YES" itemValue="1" />
                                        <f:selectItem id="no" itemLabel="NO" itemValue="0" />                                       
</h:selectOneRadio> 

但是在我的 GUI 上,我仍然可以选择单选按钮值。 请告诉我代码有什么问题..BackingBean 代码也很简单..我只是在 backingBean 中传递 0 或 1...

请指导我如何禁用用户选择

【问题讨论】:

  • 您使用的是 JSF 2.0 还是 JSF 1.2?请修正您的标签。

标签: jsf jsf-2 jsf-1.2


【解决方案1】:
<h:selectOneRadio id="wildcard"   value="#{NewService.isWildCard}" label="#{msg.org_IsWildCard}" readonly="true" layout="lineDirection">              
     <f:selectItem id="yes" itemLabel="YES" itemValue="1" itemDisabled="#{NewService.type == 1 }"/>
     <f:selectItem id="no" itemLabel="NO" itemValue="0" itemDisabled="#{NewService.type == 1 }"/>
</h:selectOneRadio> 

【讨论】:

    【解决方案2】:

    这确实是 JSF 生成的 HTML &lt;input type="radio"&gt; 元素的不直观行为。您的问题基本上有两种解决方案:

    1. 使用disabled="true" 代替readonly="true"

      <h:selectOneRadio disabled="true">
      
    2. 添加一个返回 false 的 onclick 处理程序:

      <h:selectOneRadio onclick="return false;">
      

    【讨论】:

      【解决方案3】:

      在您的 selectItems 中使用 itemDisabled 属性:

      <f:selectItem id="yes" itemLabel="YES" itemValue="1" itemDisabled="true"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-25
        • 1970-01-01
        • 2012-06-13
        • 2011-05-22
        • 1970-01-01
        • 2018-07-06
        • 1970-01-01
        相关资源
        最近更新 更多