Disable User Selection in <h:selectOneRadio>

限于喜欢 提交于 2019-12-11 11:47:13

问题


I am trying to disable user selection in tag.

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

However on my GUI I am still able to select radio button value. Please tell me what is wrong in the code..Also the BackingBean code is pretty simple..I am just passing 0 or 1 in backingBean...

Please guide me on how to disable user selection in


回答1:


This is indeed unintuitive behaviour of the JSF-generated HTML <input type="radio"> element. There are basically 2 solutions to your problem:

  1. Use disabled="true" instead of readonly="true":

    <h:selectOneRadio disabled="true">
    
  2. Add an onclick handler which returns false:

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



回答2:


Use the itemDisabled attribute in your selectItems:

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



回答3:


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


来源:https://stackoverflow.com/questions/7496859/disable-user-selection-in-hselectoneradio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!