0

I am displaying a set of questions and answer for it is either yes or no. these set of questions come from a object. the set method is not getting executed. below is my code

The objectName is the method that gets the set of questions from custom object.

<apex:repeat value="{!objectName}" var="q">
<apex:selectRadio value="{!Response}">
<apex:outputtext style="color:green;" escape="false" value="{!q.Questions__c}" />
<apex:selectOptions value="{!Answer}" />
</apex:selectRadio>

<apex:outputtext value="{!Answer}"/>
<apex:outputtext value="{!Response}"/>      
</apex:repeat>

---------------------class code----------------------

public List<SelectOption> getAnswer() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Yes','Yes'));
options.add(new SelectOption('No','No'));
return options;
}

public void setResponse(String[] Response) {


    if(Response != null)
      this.Response = Response;
    else{
        list<String> arrStr = new list<string>();
        arrStr.add('No');
      this.pResponse = arrStr;
    }
}

 public string[] getResponse(){ return Response;}
1
  • In edit mode, select your Visualforce or code and use the {} button to format so they display correctly.
    – Keith C
    Commented Mar 13, 2014 at 18:02

1 Answer 1

2

A selectradio should be backed by a single string rather than an array of strings, as the user can only ever select a single value. Thus your setters/getters need to be changed to accept/return a String rather than String[].

Also, it looks like you have a single controller property (response) that is backing all of the selectradio elements - in that case the last one to execute the setter (which Visualforce makes no guarantees about) will be the one that wins. I suspect you should be using a wrapper class to contain the element you are iterating and the response associated with it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .