1

I've been at this for the whole night. Can someone help explain how I can get a value back from a SelectRadio?

What I want to do: When they make a selection from the Radio Button, call a method. This method then checks what is selected, and assigns my To-Be-Inserted record variable some field values.

That's what I gathered from Google in regards of what I need to do to get this working.

Basically, I have got, as an example:

VF

 <apex:selectRadio >
      <apex:selectOptions value="{!recOptions}"/>
      <apex:actionSupport event="onchange" action="{!pmRecPR}" />             
 </apex:selectRadio>

APEX

    public List<SelectOption> getRecOptions()
{
  List<SelectOption> options = new List<SelectOption>();

  options.add(new SelectOption('PR', 'PR'));
  options.add(new SelectOption('A', 'A'));
  options.add(new SelectOption('NO', 'NO'));
  options.add(new SelectOption('R', 'R'));
  options.add(new SelectOption('D', 'D'));
   return options;

public void pmRecPR(){


    if (recOptions.getValue() == 'PR'){  // clearly this line doesn't work.  "variable does not exist, recOptions".
         recommendationRecord.PM_Recommendation__c='some_value';
}

when I try to declare "recOptions',

public list<selectOption> RecOptions() {get;set;}

it gives me an error:

variable does not exist:get.

But didn't I just MAKE a get for it?

Any help is really appreciated. I'm clearly a beginner and I need to get this done, and It's 2:18am. Any help, or point in the right direction would be great.

THANK YOU IN ADVANCE

1
  • its not public list<selectOption> RecOptions() {get;set;}, it should be public list<selectOption> RecOptions{get;set;} – snehakem Jun 2 '15 at 6:37
3

You need to declare a public variable in your controller for the selected valu.

VF:

<apex:selectRadio value="{!selectedValue}">
      <apex:selectOptions value="{!recOptions}"/>
      <apex:actionSupport event="onchange" action="{!pmRecPR}" />             
 </apex:selectRadio>

Controller:

    public String selectedValue {get; set;}

    public void pmRecPR(){
        if (selectedValue == 'PR'){ 
               //....blablabla
        }
    }
2
  • Thank you!!! I'm now getting a value for selectedValue! Thank you! On to the next issue... lol... My method doesn't seem to run whether I use event="onchange" or event="onselect". Ideas? – RC82 Jun 2 '15 at 13:46
  • GOT IT! I just had to move the <Apex:ActionSupport> before the <Apex:SelectActions>, but still inside <Apex:selectRadio>. Thanks again, and hopefully this helps someone down the road! – RC82 Jun 2 '15 at 13:54
0

You have to take the action support within the selectoptions tag and change the event to onselect instead of onchange. You also have to specify a public variable in class to hold the selected value.

<apex:selectRadio value="{!selectedOptionValue}">
      <apex:selectOptions value="{!recOptions}">
        <apex:actionSupport event="onselect" action="{!pmRecPR}" />
      </apex:selectOptions>
 </apex:selectRadio>

public String selectedOptionValue {get; set;}

 public List<SelectOption> getRecOptions()
{
  List<SelectOption> options = new List<SelectOption>();

  options.add(new SelectOption('PR', 'PR'));
  options.add(new SelectOption('A', 'A'));
  options.add(new SelectOption('NO', 'NO'));
  options.add(new SelectOption('R', 'R'));
  options.add(new SelectOption('D', 'D'));
   return options;

public void pmRecPR(){

    if(selectedOptionValue == 'SOMEFAKEVALUE'){
        ....
    }

    /*if (recOptions.getValue() == 'PR'){  // clearly this line doesn't work.  "variable does not exist, recOptions".
         recommendationRecord.PM_Recommendation__c='some_value';*/
}

Hope this may help.

1
  • This helped - thank you very much for responding!! – RC82 Jun 2 '15 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.