Пример #1
0
  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();
    }
  }
Пример #2
0
  @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;
    // }
  }