+ Start a Discussion
Jyosi jyosiJyosi jyosi 

Radio Button Selection values into Apex Class

Hello Everyone,

I have a pageblock section  

<apex:pageBlockSectionItem id="producttypesectionitem" >
         <apex:outputText value="Product Type" />
         <apex:selectRadio id="producttypeoptions" layout="pageDirection" value="{!ProductTypeOptions}"   onclick="myFunction(this);">
         <apex:selectOptions id="producttypeitem" value="{!ProductTypeItems}" />
              <!--<apex:selectOptions value="{!items}"/>-->

In Apex class i am using below code  I need to get the values of XX and YY based on selection of radio buttion from user in apex class

Like if they select X i need to run one query else i need to run other query .

  public String getProductTypeOptions(){
   return ProductTypeOptions;   
  public void setProductTypeOptions(String ProductTypeOptions){
    this.ProductTypeOptions = ProductTypeOptions;
  public List<SelectOption> getProductTypeItems() {
    List<SelectOption> options = new List<SelectOption>();                                  
    options.add(new SelectOption('XX','XX'));
    options.add(new SelectOption('YY','YY'));
    return options;

please help me out i am not able to get the values selected on radio button.

Thanks for help.


Value should come in ProductTypeOptions variable, not sure what is the actual issue.
Can you put a debug statement in your controller and see what the variable is printing.

You can also use the below shorthand, if there is no logic inside the getter and setter methods.
public String ProductTypeOptions{get; set;}
SandhyaSandhya (Salesforce Developers) 
Hi Jyosi,
Please refer below example code which works for me.

<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form >
        <apex:selectRadio value="{!country}">
            <apex:selectOptions value="{!items}"/>
            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
     <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}"/> 

public class sampleCon {
    String country = null;
            List<SelectOption> options = new List<SelectOption>(); 

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

If you execute this code you can see that in logs country is printing value.

Hope this helps you.

Please accept my solution as Best Answer if my answer was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards