function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pritam Patil 19Pritam Patil 19 

How to get multiple value of <apex:selectRadio> in <apex:repeat> ?

Hello all,

I want to get different values of <apex:selectRadio> which is in <apex:repeat>. How do I acheive this?

In debug logs I can see the following :-
06:36:53.0 (30801063)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.OptionOne|"One"|0x54e51697
06:36:53.0 (30901056)|SYSTEM_MODE_ENTER|true
06:36:53.0 (30931204)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
06:36:53.0 (30935083)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:44
06:36:53.0 (30944764)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.OptionOne|"Four"|0x54e51697
06:36:53.0 (31041462)|SYSTEM_MODE_ENTER|true
06:36:53.0 (31075557)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
06:36:53.0 (31079500)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:44
06:36:53.0 (31088629)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.OptionOne|"Three"|0x54e51697

'OptionOne' is the value passed from <apex:selectRadio>, and I want all the values that 'this.OptionOne' is showing, instead I only get the last value.

VF page:
 <apex:repeat value="{!fdquestionlist}" var="fd">
 <span>FeedBack Name=============></span>
<apex:outputLabel value="{!fd.Related_Feedback__r.Feedback_Name__c}" rendered="true"></apex:outputLabel>
<br />
<br />
                    <apex:outputField value="{!fd.Question__c}"/><br /><br />
          <br />   
          <br />
          <apex:selectRadio value="{!OptionOne}" id="SelectedRadio">
              <apex:selectOption itemValue="{!fd.Option_One__c}" itemLabel="{!fd.Option_One__c}"></apex:selectOption>
              <apex:selectOption itemValue="{!fd.Option_Two__c}" itemLabel="{!fd.Option_Two__c}"></apex:selectOption>
              <apex:selectOption itemValue="{!fd.Option_Three__c}" itemLabel="{!fd.Option_Three__c}"></apex:selectOption>
              <apex:selectOption itemValue="{!fd.Option_Four__c}" itemLabel="{!fd.Option_Four__c}"></apex:selectOption>
              <apex:selectOption itemValue="{!fd.Option_Five__c}" itemLabel="{!fd.Option_Five__c}"></apex:selectOption>
          </apex:selectRadio><br /><br />
   </apex:repeat>

Thanks,
Pritam
Chris  ByromChris Byrom
It looks like the problem is OptionOne on the selectRadio doesn't have any context in the repeater. It is not part of the "fd" object, so there is nothing to change its value as it goes through your questions. Your debug log shows "this.OptionOne" being set, but your loop isn't on whatever "this" is.
Pritam Patil 19Pritam Patil 19
Hey Chris,

Actually I am passing the value of the SelectRadio to a variable declared in apex class named 'OptionOne'. How do I include it in the repeater ?

Thanks.
Chris  ByromChris Byrom
You only have the one variable, so it is only going to have the last value as you are experiencing. You can either make it a part of the "fd" object, if that is where it is coming from, or use a wrapper class. This article shows how to use a wrapper class to select objects in a list. You could use the same pattern to store your "OptionOne" along with the correct "fd" record, and then loop over a list of the wrapper class. This will ensure that the value that is not part of your object will be associated with the correct object.

http://sfdcsrini.blogspot.com/2015/03/wrapper-class-usage-in-apex-and.html

There are many articles about using wrapper classes for this sort of thing, if this one doesn't make sense to you.