+ Start a Discussion

displaying a checkbox field as a radio

I have a field which is a checkbox but in my VF page I want to display it as a radio with the options of Yes or No


I am using selectradio but the problem is it is defaulting to selecting the No value. I believe the reason for this is that since the checkbox itself is not set, its value is false which is then being reflected in the radio. This is expected behavior, I guess. But I need it so that no value is selected, so we can force validation to verify they chose something.


Anybody have an idea how to do this?



	public List<SelectOption> getYesNo() { 
		List<SelectOption> options = new List<SelectOption>();
		 options.add(new SelectOption('true', 'Yes'));
		 options.add(new SelectOption('false', 'No'));
		return options;


<apex:SelectRadio id="radio" value="{!myobj.mycheckboxfield__c}">
     <apex:selectOptions value="{!yesno}"/>







Seems to be a problem with binding the VF object with a boolean.  Try creating a string property e.g.


public string fakeBoolean{get; set;}


assign that to your selecRadio and then it won't default it to 'No'


in your save action you can then transfer this string value of true/false to the boolean as required.