I had a quiz program in apex which displays the next question value when the 'Next' button is clicked and it's working fine. But when I select a value in the radio button which I had used for choices for questions, the next button does not refresh the page. I have no idea why its not working!?
VisualForce page:
<apex:page Controller="Quiz_QuestionDisplay_Controller" >
<apex:form >
<apex:actionRegion >
<apex:pageBlock >
<apex:outputPanel layout="block" id="panel" >
<apex:pageBlockSection columns="1" id="pgblksec" >
<apex:inputField value="{!current_Question.Question_No__c}" id="t1" ></apex:inputField>
<apex:inputField value="{!current_Question.Question_Detail__c}" id="t2" required="true" ></apex:inputField>
<apex:selectRadio value="{!current_Question.user_Selected_Ans__c}" >
<apex:selectOptions value="{!choices}"/>
<apex:actionSupport event="onchange" action="{!checkSelectedValue}" reRender="none"/>
</apex:selectRadio><p/>
<apex:outputText value="{!index}" />
<apex:outputText value="{!size}"/>
<apex:commandButton value="next" action="{!next_Click}" rerender="panel"/>
<apex:commandButton value="prev" action="{!prev_Click}" rerender="panel"/>
<apex:commandButton value="submit" action="{!user_Submit}" />
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>
Controller:
public class Quiz_QuestionDisplay_Controller {
public Integer index{get;set;}
//Integer chosen_Value {get;set;}
Map<Integer,Decimal> answers;
public List<Question__c> questions{get;set;}
public List<SelectOption> choices=new List<SelectOption>();
public Question__c current_Question;
public Integer size{get;set;}
public Quiz_QuestionDisplay_Controller()
{
index=0;
count=0;
//user_Selected_Ans=-1;
answers=new Map<Integer,Decimal>();
questions= [SELECT Question_No__c,user_Selected_Ans__c,Question_Detail__c,choice1__c,choice2__c,choice3__c,choice4__c,ans__c FROM Question__c LIMIT 1000];
size=questions.size();
current_Question=questions.get(index);
}
public List<SelectOption> getChoices()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('choice1',current_Question.choice1__c));
options.add(new SelectOption('choice2',current_Question.choice2__c));
options.add(new SelectOption('choice3',current_Question.choice3__c));
options.add(new SelectOption('choice4',current_Question.choice4__c));
return options;
}
public void checkSelectedValue()
{
Question__c ob=questions.get(index);
System.debug('Selected value is: ' + ob.user_Selected_Ans__c);
System.debug('Selected value is: ' + current_Question.user_Selected_Ans__c);
}
public Question__c getCurrent_Question()
{
return current_Question;
}
public void setQuestion(Question__c value)
{
current_Question=value;
}
public void next_Click()
{
// PageReference pageRef = ApexPages.currentPage();
Integer org=index;
index++;
if(index==size)
index=0;
answers.put(org,questions.get(org).user_Selected_Ans__c);
current_Question=questions.get(index);
//return pageRef;
}
public void prev_click()
{
Integer org=index;
// PageReference pageRef = ApexPages.currentPage();
//error to be handled
index--;
if(index==-1)
index=size-1;
answers.put(org,questions.get(org).user_Selected_Ans__c);
current_Question=questions.get(index);
// return pageRef;
}
public void user_Submit()
{
}
}
<p/>
tag.