You need to sign in to do that
Don't have an account?
Need help on online examination vf page and class
-----------------------------------page-----------------------------------
<apex:page sidebar="false" showheader="false" controller="QuestionAnswers">
<script>
function selectedAnswer(){
actionFunc1();
}
</script>
<div style="height:620px;width:1346px;padding:5px;overflow:auto;background-color:#E6F8E0;border:1px solid gray;">
<h><center><font size="6"><u>Examination Page</u></font></center></h><br/>
<apex:form >
<apex:actionFunction name="actionFunc1" action="{!calculateResult}" rerender="proxy"/>
<apex:outputPanel id="radionButton" >
<h1 style="margin-left:100px;"><font size="3">Question Number : {!count+1} </font><br/></h1><br/>
<h2 style="margin-left:100px;"><font size="3">Question : </font></h2>
<apex:outputtext value="{!question}"/>
<apex:selectRadio value="{!selectedValue}" layout="pageDirection" style="margin-left:100px;" onclick="selectedAnswer();">
<br/><apex:selectOptions value="{!options}"/>
</apex:selectRadio>
</apex:outputPanel>
<apex:outputPanel id="buttons">
<br/><apex:commandButton action="{!next}" rerender="proxy,radionButton,buttons" value="next" style="margin-left:100px;" rendered="{!IF(count<examQuestion.size-1,True,False)}"/>
<apex:commandButton action="{!previous}" rerender="proxy,radionButton,buttons" value="previous" rendered="{!IF(count>0,True,false)}"/>
</apex:outputPanel>
</apex:form>
</div>
</apex:page>
------------------------------------------------------class--------------------------------------------------------
public class QuestionAnswers {
public String question{get;set;}
public List<SelectOption> options{get;set;}
public Map<String,String> junctionMap{get;set;}//2nd way to implement
public String selectedValue = null;//2nd way to implement
public Map<String,String> resultCal{get;set;}
public List<Online_Examination__c> examQuestion{get;set;}
public List<Answer__c> answers{get;set;}
public Integer count{get;set;}
public QuestionAnswers(){
count = 0;
resultCal = new Map<String,String>();
options = new List<SelectOption>();
junctionMap = new Map<String,String>();//2nd way to implement
examQuestion = [select Question__c,Type__c,Id from Online_Examination__c];
prepareMap();
}
public void next(){
count = count+1;
prepareMap();
}
public void previous() {
count = count-1;
prepareMap();
}
public void prepareMap(){
question = examQuestion[count].Question__c;
answers = [select Id,Choice__c,CorrectAnswer__c from Answer__c where Online_Examination__c=:examQuestion[count].Id];
options.clear();
for(Answer__c listAns : answers){
options.add(new SelectOption(listAns.Choice__c,listAns.Choice__c));
}
}
public void calculateResult() {
junctionMap.put(examQuestion[count].Question__c,selectedValue);
}
public String getselectedValue() {
for(String s : junctionMap.keyset()){
system.debug('Key is'+s);
system.debug('Value is'+junctionMap.get(s));
}
if(junctionMap.get(examQuestion[count].Question__c) == NULL){
return selectedValue;
}else { return junctionMap.get(examQuestion[count].Question__c);}
}
public void setselectedValue(String selectedValue){
this.selectedValue = selectedValue;
system.debug('set Selected Value:::'+selectedValue);
}
}
Hi,i have pasted the page and class here. Here i am fetching first all the question records from Online_Examination__c object then later on i searched corresponding option from child object . at last when user selects values for a specific question a map stores the values against question . which i used to return the selected option when the user come back previous question .But the problem is that it's working soemtimes i mean not for all questions. Please help.