You need to sign in to do that
Don't have an account?
Steve_Finlay
How to set the selected radio button?
In the following code sample...
<apex:selectRadio value="{!CustomObject__c.CustomField__c}" >
<apex:selectOption itemValue="true" itemLabel="Yes" />
<apex:selectOption itemValue="false" itemLabel="No" />
</apex:selectRadio>
The second item "No" is selected by default. I want the first item "Yes" to be the one that is, by default, the selected item.
Steve
Using controller you can have any radio button default selected .
Below example, I have made 'CANADA' country as default selected.
/*** Controller ***/
public class sampleCon {
String country = 'CANADA';
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico')); return options;
}
public String getCountry() {
return country;
}
public void setCountry(String country) { this.country = country; }
}
<!-- Page: -->
<apex:page controller="sampleCon">
<apex:form >
<apex:selectRadio value="{!country}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:outputText value="{!country}"/>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
Hope above example helps you.
Ganesh
All Answers
Using controller you can have any radio button default selected .
Below example, I have made 'CANADA' country as default selected.
/*** Controller ***/
public class sampleCon {
String country = 'CANADA';
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico')); return options;
}
public String getCountry() {
return country;
}
public void setCountry(String country) { this.country = country; }
}
<!-- Page: -->
<apex:page controller="sampleCon">
<apex:form >
<apex:selectRadio value="{!country}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:outputText value="{!country}"/>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
Hope above example helps you.
Ganesh
Ok, thanks, I'll try it out.
hey sfinlay
this is not working in my case
did this work in your problem
if no then please post the alternative solution if you found.
It works dude Thanks .
{!CustomObject__c.CustomField__c} if value of this custom fileld is true then 'Yes' will be selected..