/** * @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"); }
@SuppressWarnings("unchecked") public void generateNextQuestion(AjaxBehaviorEvent event) throws IOException { List<ExamVO> examVOList = new ArrayList<ExamVO>(); List<QuestionVO> questionVOList = new ArrayList<QuestionVO>(); // if (StringUtils.equals("Submit", getRenderButton())) { // return "error"; // } else { examPaperVO = (ExamPaperVO) SessionHelper.getValueFromSession("EXAMINFO"); String quesSeqStr = String.valueOf(SessionHelper.getValueFromSession("quesSeqNo")); int quesSeq; if (StringUtils.isNumeric(quesSeqStr)) { quesSeq = Integer.valueOf(quesSeqStr); // int quesSeq = getQuesSeqNo(); } else { quesSeq = 0; } questionVOList = (List<QuestionVO>) SessionHelper.getValueFromSession("examQuestionList"); QuestionVO currentQuestionVO = questionVOList.get(quesSeq); ExamVO examVO = new ExamVO(); examVO.setQuesId(currentQuestionVO.getQuestionId()); examVO.setExamAns(getExamAns()); if (StringUtils.equals(currentQuestionVO.getAnswer(), getExamAns())) { examVO.setExamResult("Correct"); } else { examVO.setExamResult("Wrong"); } examVOList = (List<ExamVO>) SessionHelper.getValueFromSession("examVOList"); examVOList.add(examVO); SessionHelper.removeValueFromSession("examVOList"); SessionHelper.setValueToSession("examVOList", examVOList); quesSeq++; // setQuesSeqNo(quesSeq); if (questionVOList.size() > quesSeq) { if (ExamConstants.QUES_TYPE_PARA.equals(questionVOList.get(quesSeq).getQuestionCategory())) { setExamQuesPara(questionVOList.get(quesSeq).getQuestion()); SessionHelper.setValueToSession("examQuesPara", getExamQuesPara()); quesSeq++; setQuestionVO(questionVOList.get(quesSeq)); setQuesParaStyle("display : inline;"); setQuesImgStyle("display : none;"); SessionHelper.setValueToSession("currentQuesType", ExamConstants.QUES_TYPE_PARA); } else if (ExamConstants.QUES_TYPE_IMG.equals( questionVOList.get(quesSeq).getQuestionCategory())) { setExamQuesImg(questionVOList.get(quesSeq).getQuestion()); SessionHelper.setValueToSession("examQuesImg", getExamQuesImg()); quesSeq++; setQuestionVO(questionVOList.get(quesSeq)); setQuesParaStyle("display : none;"); setQuesImgStyle("display : inline;"); SessionHelper.setValueToSession("currentQuesType", ExamConstants.QUES_TYPE_IMG); } else if (ExamConstants.QUES_TYPE_SINGLE.equals( questionVOList.get(quesSeq).getQuestionCategory())) { setExamQuesPara(""); setQuestionVO(questionVOList.get(quesSeq)); setQuesParaStyle("display : none;"); setQuesImgStyle("display : none;"); } else { String currentQuesType = (String) SessionHelper.getValueFromSession("currentQuesType"); if (StringUtils.equals(ExamConstants.QUES_TYPE_PARA, currentQuesType)) { String quesPara = (String) SessionHelper.getValueFromSession("examQuesPara"); setExamQuesPara(quesPara); setQuestionVO(questionVOList.get(quesSeq)); setQuesParaStyle("display : inline;"); setQuesImgStyle("display : none;"); } else if (StringUtils.equals(ExamConstants.QUES_TYPE_IMG, currentQuesType)) { String quesImg = (String) SessionHelper.getValueFromSession("examQuesImg"); setExamQuesImg(quesImg); setQuestionVO(questionVOList.get(quesSeq)); setQuesParaStyle("display : none;"); setQuesImgStyle("display : inline;"); } } } SessionHelper.setValueToSession("quesSeqNo", quesSeq); setExamAns(null); for (ExamVO examVO1 : examVOList) { System.out.println("Ques Id: " + examVO1.getQuesId()); System.out.println(examVO1.getExamAns()); System.out.println(examVO1.getExamResult()); } if (StringUtils.equals(isExamTimeUp, "Y")) { saveStudentAns(examVOList); } if (questionVOList.size() == quesSeq + 1) { setRenderButton("Submit"); } else if (questionVOList.size() > quesSeq + 1) { setRenderButton("Next"); } else { saveStudentAns(examVOList); } // return null; // } }