function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
viswadaviswada 

Set Timer for vf page( Online exam vf page)

HI All,

 

       I have created  on vf page  to dispaly questions(records) from my custom object  and  provide result  for the questions  in same vf page.  Now  my senarios . I need to set time  for vf page. like supoose in  my vf page there are 20 questions. for 20 questions ineed to set 20 min time  . If end user could n't complete the test  with in 20 mins , that question should not appear automatically,   i am placing my vf page and controller, plz suggest me how to implement this  senario.

 

vf page:

-------------

<apex:page controller="Records20" sidebar="false" >
<apex:form >
<apex:outputpanel rendered="{!displayRecords}" >

<apex:pageblock Title="Answers the Questions">

<b><apex:outputText value="Your Time Starts Now: {!Timer}:00 Min" id="counter"/></b>
<apex:actionPoller action="{!incrementCounter}" rerender="counter ,button" interval="15"/>
<br/>
<br/>

<apex:pageBlockButtons location="bottom">

<apex:commandButton value="Submit" action="{!saveAnswer}" id="button"/><br/>
</apex:pageBlockButtons>
<apex:repeat value="{!items1}" var="it">
<apex:outputText value="{!it.intSerial}"> </apex:outputText>).&nbsp;<apex:outputText value="{!it.strQuestion}"></apex:outputText>
<apex:SelectRadio value="{!it.answer12}">
<apex:selectoptions value="{!it.itemsWrap}"/>
</apex:SelectRadio><br/>
</apex:repeat>
</apex:pageblock>
</apex:outputpanel>
YOUR RESULT IS:&nbsp;&nbsp;<apex:outputText value="{!intCount}"></apex:outputText>
</apex:form>
</apex:page>

__________

controlle---

 

 

public class Records20{

public Integer Timer;
public boolean displayRecords{set;get;}
public string answer1{set;get;}
public List<selectOption> selItems {get;set;}
public integer intCount{get;set;}
list<wrapperQuestions> objwraplst = new list<wrapperQuestions>();
list<Questiuons__c> ques=new list<Questiuons__c>();


public Records20()
{
Timer=0;
displayRecords=true;
list <Questiuons__c> ret=[SELECT id,Question__c,Answers__c,Correctanswer__c FROM Questiuons__c LIMIT 20 ];
ret = ObjectRandomizer.randomizeList (ret);
integer serial=0;
for(Questiuons__c a :ret )
{
System.debug('aaa'+a);
String s = a.Answers__c;
list<string> st =s.split(',');
wrapperQuestions objWrap = new wrapperQuestions();
objWrap.strQuestion = a.Question__c;
objWrap.correctAnswer=a.Correctanswer__c;
serial=serial+1;
objWrap.intSerial=serial;
selItems = new List<selectOption>();
for(String str:st)
{
selItems.add(new SelectOption(str,str));

objWrap.itemsWrap=selItems;

}

objwraplst.add(objWrap);

}
}

public void saveAnswer()
{
intCount=0;
for(wrapperQuestions objwrap:objwraplst)
{
system.debug('::::::::::::'+objwrap.answer12);
if(objwrap.answer12==objwrap.correctAnswer)
{
//intCount = intCount+1;
intCount++;
displayRecords=false;

}else
displayRecords=false;
}

}

public PageReference incrementCounter() {
if(Timer<=5)
Timer++;
system.debug('@@@@@@@@@@@'+timer);
return null;
}

public Integer getTimer() {
system.debug('!!!!!!!!!!!!!!'+timer);
return Timer;
}
public list<wrapperQuestions> getitems1()
{
return objwraplst;
}


public class wrapperQuestions
{
public string strQuestion{get;set;}
public integer intSerial{get;set;}
public List<selectOption> itemsWrap {get;set;}
public string answer12{set;get;}
public string correctAnswer{set;get;}

}

}

  Any one can help me

 

marella1800marella1800

Hi Viswada,Hope you got the answer for the above,please let me know how you have created timer on visualforce page,itz very helpful fo me.

 

Thanx in advance

marella1800marella1800

Hi Viswada,Hope you got the answer for the above,please let me know how you have created timer on visualforce page,itz very helpful for me.

 

bremmibremmi

hai viswa

 could u plz send the deatils of ur senario and how many custome objects,fields had u taken? 

plz send to my mail id: brahmam.cmrit@gmail.com