You need to sign in to do that
Don't have an account?
Pritam Patil 19
Blank value of Radio Button getting inserted
Hello,
I am displaying questions on a VF page and their options in form of radio buttons, but when I try to get the selected values of all the radio buttons and insert them for each record, blank value is passed.
Following is my code :
VF PAGE :
<apex:page controller="DisplayController" sidebar="false">
<apex:form >
<apex:repeat value="{!Questions}" var="q">
<apex:outputField value="{!q.Related_Question__r.Question__c}"/>
<apex:selectRadio value="{!q.Related_Question__r.Selected_Value__c}" id="RadioButtonValue" >
<apex:selectOptions value="{!Options}" ></apex:selectOptions>
</apex:selectRadio><br /><br />
</apex:repeat>
<apex:commandButton action="{!SubmitSurvey}" value="Save" title="Save"/>
</apex:form>
</apex:page>
APEX CONTROLLER :
public with sharing class DisplayController {
Public Survey_Main__c mainobj{get;set;}
Public Survey_Question_Table__c questobj{get;set;}
Public Survey_Option_table__c optobje{get;set;}
Public List<Survey_Main__c> mainList{get;set;}
Public List<Survey_Question_Table__c> questList{get;set;}
Public List<Survey_Option_Table__c> optList{get;set;}
Public String SelectedValue{get;set;}
Public DisplayController(){
}
Public List<Survey_Option_Table__c> getQuestions(){
optList = [select id, name,Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__r.Question__c,Related_Question__r.Selected_Value__c,Related_Question__r.Related_Survey__c from Survey_Option_Table__c where Related_Question__r.Related_Survey__c = 'a0d28000001GVcw'];
return optList;
}
Public List<SelectOption> getOptions(){
questList = [select id, name, Question__c,Selected_Value__c,Related_Survey__c from Survey_Question_Table__c where Related_Survey__c = 'a0d28000001GVcw'];
optList=[select id, name, Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__c from Survey_Option_Table__c where Related_Question__c =: questList];
List<SelectOption> options = new List<SelectOption>();
for(integer i=0;i<1;i++)
{
system.debug('++++++++++++++OPTION BLOCK+++++++++++++++'+optList[i]);
options.add(new SelectOption('Option One','Option One'));
options.add(new SelectOption('Option Two','Option Two'));
options.add(new SelectOption('Option Three','Option Three'));
options.add(new SelectOption('Option Four','Option Four'));
options.add(new SelectOption('Option Five','Option Five'));
}
return options;
}
public PageReference SubmitSurvey() {
for (Survey_Option_Table__c sqItem : getQuestions()) {
if(sqItem.Related_Question__r.Selected_Value__c != null || sqItem.Related_Question__r.Selected_Value__c != ' '){
//Inserting The Survey Result
Survey_Result__c SurveyResult = new Survey_Result__c(
Answer__c = sqItem.Related_Question__r.Selected_Value__c,
Related_Question__c = sqItem.Related_Question__r.Id
);
insert SurveyResult;
} else{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Atleast one value'));
}
}
return null;
}
Need help on this...Urgent !
Thanks.
I am displaying questions on a VF page and their options in form of radio buttons, but when I try to get the selected values of all the radio buttons and insert them for each record, blank value is passed.
Following is my code :
VF PAGE :
<apex:page controller="DisplayController" sidebar="false">
<apex:form >
<apex:repeat value="{!Questions}" var="q">
<apex:outputField value="{!q.Related_Question__r.Question__c}"/>
<apex:selectRadio value="{!q.Related_Question__r.Selected_Value__c}" id="RadioButtonValue" >
<apex:selectOptions value="{!Options}" ></apex:selectOptions>
</apex:selectRadio><br /><br />
</apex:repeat>
<apex:commandButton action="{!SubmitSurvey}" value="Save" title="Save"/>
</apex:form>
</apex:page>
APEX CONTROLLER :
public with sharing class DisplayController {
Public Survey_Main__c mainobj{get;set;}
Public Survey_Question_Table__c questobj{get;set;}
Public Survey_Option_table__c optobje{get;set;}
Public List<Survey_Main__c> mainList{get;set;}
Public List<Survey_Question_Table__c> questList{get;set;}
Public List<Survey_Option_Table__c> optList{get;set;}
Public String SelectedValue{get;set;}
Public DisplayController(){
}
Public List<Survey_Option_Table__c> getQuestions(){
optList = [select id, name,Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__r.Question__c,Related_Question__r.Selected_Value__c,Related_Question__r.Related_Survey__c from Survey_Option_Table__c where Related_Question__r.Related_Survey__c = 'a0d28000001GVcw'];
return optList;
}
Public List<SelectOption> getOptions(){
questList = [select id, name, Question__c,Selected_Value__c,Related_Survey__c from Survey_Question_Table__c where Related_Survey__c = 'a0d28000001GVcw'];
optList=[select id, name, Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__c from Survey_Option_Table__c where Related_Question__c =: questList];
List<SelectOption> options = new List<SelectOption>();
for(integer i=0;i<1;i++)
{
system.debug('++++++++++++++OPTION BLOCK+++++++++++++++'+optList[i]);
options.add(new SelectOption('Option One','Option One'));
options.add(new SelectOption('Option Two','Option Two'));
options.add(new SelectOption('Option Three','Option Three'));
options.add(new SelectOption('Option Four','Option Four'));
options.add(new SelectOption('Option Five','Option Five'));
}
return options;
}
public PageReference SubmitSurvey() {
for (Survey_Option_Table__c sqItem : getQuestions()) {
if(sqItem.Related_Question__r.Selected_Value__c != null || sqItem.Related_Question__r.Selected_Value__c != ' '){
//Inserting The Survey Result
Survey_Result__c SurveyResult = new Survey_Result__c(
Answer__c = sqItem.Related_Question__r.Selected_Value__c,
Related_Question__c = sqItem.Related_Question__r.Id
);
insert SurveyResult;
} else{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Atleast one value'));
}
}
return null;
}
Need help on this...Urgent !
Thanks.
APEX CONTROLLER :
public with sharing class DisplayController {
Public Survey_Main__c mainobj{get;set;}
Public Survey_Question_Table__c questobj{get;set;}
Public Survey_Option_table__c optobje{get;set;}
Public List<Survey_Main__c> mainList{get;set;}
Public List<Survey_Question_Table__c> questList{get;set;}
Public List<Survey_Option_Table__c> optList{get;set;}
Public String SelectedValue{get;set;}
Public DisplayController(){
}
Public List<Survey_Option_Table__c> getQuestions(){
optList = [select id, name,Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__r.Question__c,Related_Question__r.Selected_Value__c,Related_Question__r.Related_Survey__c from Survey_Option_Table__c where Related_Question__r.Related_Survey__c = 'a0d28000001GVcw'];
return optList;
}
Public List<SelectOption> getOptions(){
questList = [select id, name, Question__c,Selected_Value__c,Related_Survey__c from Survey_Question_Table__c where Related_Survey__c = 'a0d28000001GVcw'];
optList=[select id, name, Option_One__c,Option_Two__c,Option_Three__c,Option_Four__c,Option_Five__c,Answer__c, Related_Question__c from Survey_Option_Table__c where Related_Question__c =: questList];
List<SelectOption> options = new List<SelectOption>();
for(integer i=0;i<1;i++)
{
system.debug('++++++++++++++OPTION BLOCK+++++++++++++++'+optList[i]);
options.add(new SelectOption('Option One','Option One'));
options.add(new SelectOption('Option Two','Option Two'));
options.add(new SelectOption('Option Three','Option Three'));
options.add(new SelectOption('Option Four','Option Four'));
options.add(new SelectOption('Option Five','Option Five'));
}
return options;
}
public String getSelectedValue(){
return SelectedValue;
}
public void setSelectedValue(String SelectedValue){
this.SelectedValue = SelectedValue;
}
public PageReference SubmitSurvey() {
for (Survey_Option_Table__c sqItem : getQuestions()) {
if(sqItem.Related_Question__r.Selected_Value__c != null || sqItem.Related_Question__r.Selected_Value__c != ' '){
//Inserting The Survey Result
Survey_Result__c SurveyResult = new Survey_Result__c(
Answer__c = sqItem.Related_Question__r.Selected_Value__c,
Related_Question__c = sqItem.Related_Question__r.Id
);
insert SurveyResult;
} else{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Select Atleast one value'));
}
}
return null;
}
It did not work. Actually there is no use of getting setting the variable 'SelectedValue', because I am not inserting that.
Thanks.