private void populateExamQuestionSet() { try { String examName = FacesContext.getCurrentInstance() .getExternalContext() .getRequestParameterMap() .get("examName"); String paperNo = FacesContext.getCurrentInstance() .getExternalContext() .getRequestParameterMap() .get("paperNo"); SessionHelper.setValueToSession("examName", examName); SessionHelper.setValueToSession("paperNo", paperNo); System.out.println("--- " + examName + " -- " + paperNo); ExamDAO examDAO = new ExamDAO(); examPaperVO = examDAO.getExamInfoFromNameAndPaperNo(examName, paperNo); QuestionDAO questionDAO = new QuestionDAO(); List<QuestionVO> examQuestionList = questionDAO.getExamQuestions(examName, paperNo); System.out.println("Exam list size :::" + examQuestionList.size()); SessionHelper.setValueToSession("EXAMINFO", examPaperVO); SessionHelper.setValueToSession("examQuestionList", examQuestionList); // setQuestionVOList(examQuestionList); QuestionVO firstQuestionVO = examQuestionList.get(0); if (ExamConstants.QUES_TYPE_SINGLE.equals(firstQuestionVO.getQuestionCategory())) { setExamQuesPara(""); setQuestionVO(firstQuestionVO); setQuesParaStyle("display : none;"); setQuesImgStyle("display : none;"); SessionHelper.setValueToSession("quesSeqNo", 0); SessionHelper.setValueToSession("currentQuesType", ExamConstants.QUES_TYPE_SINGLE); } else if (ExamConstants.QUES_TYPE_PARA.equals(firstQuestionVO.getQuestionCategory())) { setExamQuesPara(firstQuestionVO.getQuestion()); setQuestionVO(examQuestionList.get(1)); setQuesParaStyle("display : inline;"); setQuesImgStyle("display : none;"); SessionHelper.setValueToSession("examQuesPara", getExamQuesPara()); SessionHelper.setValueToSession("quesSeqNo", 1); SessionHelper.setValueToSession("currentQuesType", ExamConstants.QUES_TYPE_PARA); } else if (ExamConstants.QUES_TYPE_IMG.equals(firstQuestionVO.getQuestionCategory())) { setExamQuesImg(firstQuestionVO.getQuestion()); setQuestionVO(examQuestionList.get(1)); setQuesParaStyle("display : none;"); setQuesImgStyle("display : inline;"); SessionHelper.setValueToSession("examQuesImg", getExamQuesImg()); SessionHelper.setValueToSession("quesSeqNo", 1); SessionHelper.setValueToSession("currentQuesType", ExamConstants.QUES_TYPE_IMG); } // setPopulate(false); setTimeLeft(examPaperVO.getExamDuration()); } catch (Exception e) { e.printStackTrace(); } }
/** * @param examVOList * @return * @throws IOException */ private void saveStudentAns(List<ExamVO> examVOList) throws IOException { int examMarks = 0; for (ExamVO examVO1 : examVOList) { if (StringUtils.equals("Correct", examVO1.getExamResult())) { examMarks++; } } setExamObtainedMarks(String.valueOf(examMarks)); SessionHelper.setValueToSession("examObtainedMarks", String.valueOf(examMarks)); // Save student answer in DB ExamDAO examDAO = new ExamDAO(); String examName = (String) SessionHelper.getValueFromSession("examName"); String paperNo = (String) SessionHelper.getValueFromSession("paperNo"); String studId = (String) SessionHelper.getValueFromSession("userID"); examDAO.setStudExamAns(studId, examVOList, examName, paperNo, getExamObtainedMarks()); // return "examResultPage"; FacesContext.getCurrentInstance().getExternalContext().redirect("examResult.xhtml"); }