Пример #1
0
 private void validateNumberOfQuestions(CreateQuestion createQuestion, Errors errors) {
   ValidationUtils.rejectIfEmpty(
       errors,
       "createQuestion.numCorrect",
       "required.numCorrect",
       "Correct answers have to be minimum 1");
   ValidationUtils.rejectIfEmpty(
       errors,
       "createQuestion.numIncorrect",
       "required.numIncorrect",
       "Incorrect answers have to be minimum 3");
   if (createQuestion.getNumCorrect() + createQuestion.getNumIncorrect() <= 0)
     errors.rejectValue("", "invalid.answer.number", "you need to add at lest one answer");
 }
Пример #2
0
 private void validateAnswerFields(CreateQuestion createQuestion, Errors errors) {
   Question question = createQuestion.getQuestion();
   if (question.getAnswers().size()
       != createQuestion.getNumCorrect() + createQuestion.getNumIncorrect())
     errors.rejectValue("", "invalid.answers", "all answers are mandatory");
   for (Answer answer : question.getAnswers()) {
     if (!answer.isValid()) {
       errors.rejectValue(
           "",
           "invalid.answers",
           "all answers and their hints are mandatory and cannot be left blank");
       return;
     }
   }
 }