You need to sign in to do that
Don't have an account?

set time for Vf page (like online exam)
HI All,
I have created one 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 to set time and 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>). <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: <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
There's some code in this blog post of mine:
http://bobbuzzard.blogspot.co.uk/2011/06/automatic-dashboard-refresh.html
that counts down a timer to refresh a dashboard via an actionfunction - it should be straightforward to adapt this to close off your page once the timer has expired.
Hi can you please let me know how to set timer and automate it on Vf page,
Thanx in advance
<script language="JavaScript" type="text/javascript">
var sec = 00; // set the seconds
var min = 60; // set the minutes
function countDown() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1; }
else {
min = min; }
if (sec<=9) { sec = "0" + sec; }
time = (min<=9 ? "0" + min : min) + " min and " + sec + " sec ";
if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}
window.onload = countDown;
</script>