问题
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:
Use
disabled="true"
instead ofreadonly="true"
:<h:selectOneRadio disabled="true">
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