use of org.survey.model.poll.Question in project survey by markoniemi.
the class PollController method addQuestion.
// TODO use GET
@RequestMapping(value = "/poll/addQuestion", method = RequestMethod.POST)
public ModelAndView addQuestion(@ModelAttribute Poll poll) {
// Poll poll = pollService.findOne(name);
log.debug("editPoll() - found poll: " + poll);
if (poll != null) {
if (poll.getQuestions() == null) {
poll.setQuestions(new ArrayList<Question>());
}
Question question = new Question();
question.setPoll(poll);
poll.getQuestions().add(question);
}
ModelAndView model = new ModelAndView();
model.setViewName("/poll/poll");
model.addObject("poll", poll);
// model.addObject("roles", getRolesAsMap());
return model;
}
use of org.survey.model.poll.Question in project survey by markoniemi.
the class EditPollBean method addQuestion.
/**
* Called from editPoll.xhtml page when user presses Add question button.
*/
public void addQuestion() {
if (poll.getQuestions() == null) {
poll.setQuestions(new ArrayList<Question>());
}
Question question = new Question();
question.setType(QuestionType.LABEL);
question.setPoll(poll);
poll.getQuestions().add(question);
}
use of org.survey.model.poll.Question in project survey by markoniemi.
the class EditPollBeanTest method addQuestion.
@Ignore("poll is attached and test does not represent the situation in runtime")
@Test
public void addQuestion() {
addPoll();
String result = editPollBean.editPoll();
Assert.assertEquals("editPollBean.editPoll returned an unexpected value", "editPoll", result);
editPollBean.addQuestion();
Assert.assertNotNull(editPollBean.getPoll().getQuestions());
Assert.assertEquals(1, editPollBean.getPoll().getQuestions().size());
Question question = editPollBean.getPoll().getQuestions().get(0);
question.setText("text1");
result = editPollBean.savePoll();
Assert.assertEquals("editPollBean.savePoll returned an unexpected value", "pollSaved", result);
Poll pollFromDatabase = pollService.findOne("poll");
Assert.assertNotNull("registered poll was not added to database", pollFromDatabase);
Assert.assertEquals(1, pollFromDatabase.getQuestions().size());
Assert.assertEquals("text1", pollFromDatabase.getQuestions().get(0).getText());
}
use of org.survey.model.poll.Question in project survey by markoniemi.
the class EditPollBean method questionTypeChanged.
/**
* Called from editPoll.xhtml page when user changes a question type.
* editPoll.xhtml contains a selectOneMenu with
* valueChangeListener="#{editPollBean.questionTypeChanged(status.index)}"
*/
public void questionTypeChanged(int index) {
log.debug("index: {}", index);
Question question = poll.getQuestions().get(index);
log.debug("oldQuestion.type: {}", question.getType());
// QuestionType questionType = QuestionType.valueOf(QuestionType.class, question.getType());
// log.debug("questionType: {}", questionType);
// Question newQuestion = QuestionFactory.createQuestionFrom(question, questionType, poll);
// poll.getQuestions().set(index, newQuestion);
}
Aggregations