Link to home
Start Free TrialLog in
Avatar of Manikandan Thiagarajan
Manikandan ThiagarajanFlag for India

asked on

ould you please give me the code with JSF for radio button

i want to check only one radio button in group .it would not alllow multible checks

my program would allow multible checks

please modify my code with JSF
<%@ page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<f:view>
	<html>
	<head>
	<title>Site Administration Dashboard</title>
	</head>
	<body>
	<script type="text/javascript"> 
 		var reloadName;
 		var reloadValue;
 		
        function displayPropertyVal(name,value,keyId){ 
           
           	alert('doSomethingInline: ' + name);        
           	alert('doSomethingInline: ' + value);
            document.getElementById("myform:name").value = name; 
            document.getElementById("myform:value").value = value;
            document.getElementById("myform:keyId").value =keyId;          
            //document.getElementsById("keyId").value = row.childNodes[3].innerText;
            reloadName =name;
            reloadValue =value;
            //document.getElementById("Save").disabled=false;
            //document.getElementById("Reload").disabled=false;
            //document.getElementById("Add").disabled=true;
        }
        function getValues()
        {
         document.getElementById("myform:name").value =reloadName;
         document.getElementById("myform:value").value =reloadValue;
        }
	</script>

	<h:form id="myform">

		<h:selectOneMenu id="environment"
			value="#{propertyLoad.propertyLoadVO.environment}"
			onchange="this.form.submit()"
			valueChangeListener="#{propertyLoad.getProperty}">
			<f:selectItem id="DevServer" itemLabel="DevServer"
				itemValue="DevServer" />
			<f:selectItem id="ProdServer" itemLabel="ProdServer"
				itemValue="ProdServer" />
			<f:selectItem id="UAT" itemLabel="UAT" itemValue="UAT" />
		</h:selectOneMenu>


		<h:commandButton value="Reload" onclick="getValues()" />
		<table>
			<tr>
				<td>PropertyName:</td>

				<td><h:inputText id="name"
					value="#{propertyLoad.propertyLoadVO.name}">
				</h:inputText></td>

			</tr>
			<tr>
				<td>PropertyValue:</td>

				<td><h:inputText id="value"
					value="#{propertyLoad.propertyLoadVO.value}">
				</h:inputText></td>

			</tr>
			
			<tr>
				<td><h:inputText id="keyId"
					value="#{propertyLoad.propertyLoadVO.keyId}" style="display:none">
				</h:inputText></td>

			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><h:commandButton value="Add" action="#{propertyLoad.add}" /></td>

				<td><h:commandButton value="Save" action="#{propertyLoad.save}" /></td>

			</tr>
		</table>

		<h:dataTable id="dt1" value="#{propertyLoad.property}" var="item"
			bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3"
			width="50%">
			<f:facet name="header">
				<h:outputText value="CWS-Dashboard administration" />
			</f:facet>

			<h:column>
				<f:facet name="header">
					<h:outputText styleClass="outputText" value="Select" id="text1"></h:outputText>
				</f:facet>
				<h:selectOneRadio id="radio" layout="pageDirection" onclick="displayPropertyVal('#{item.name}','#{item.value}','#{item.keyId}');">
					<f:selectItem id="selectRadio" itemLabel="#{item.name}" itemValue="#{item.value}" />
				</h:selectOneRadio>
			</h:column>

			<h:column>
				<f:facet name="header">
					<h:outputText value="Name" />
				</f:facet>
				<h:outputText value="#{item.name}" />
			</h:column>

			<h:column>
				<f:facet name="header">
					<h:outputText value="Value" />
				</f:facet>
				<h:outputText value="#{item.value}" />
			</h:column>

			<h:column >
				<f:facet name="header"> 
					<h:outputText value="KeyID" style="display:none"/>
				</f:facet>
				<h:outputText value="#{item.keyId}" style="display:none" />
			</h:column>

			<f:facet name="footer">
				<h:outputText value="The End" />
			</f:facet>
		</h:dataTable>
		<br>

	</h:form>
	</body>
	</html>
</f:view>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of girionis
What exactly are you trying to do? You only have one item (and thus one radio button) within the selectOneRadio element.
Avatar of Manikandan Thiagarajan

ASKER

i found that answer
That was a known problem with radio button groups when each radio was in a separate table cell, because JSF changes radio names automatically and consequently they don't behave as they are in the same group.

I implemented the "custom component" solution (link I posted) in my environment and it worked like a charm.

What did you do to correct the problem?
using javascript i would deselect the other radio button
Yes, you did it that way, but I still provided a valid solution that's better then overriding the component behavior with JavaScript.
sorry for that