Find your content:

Search form

You are here

Set method not called in apex:repeat

 
Share

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

Attribution to: user7341

Possible Suggestion/Solution #1

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.


Attribution to: Bob Buzzard
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30124

My Block Status

My Block Content