Search in sources :

Example 1 with Question

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Question(org.survey.model.poll.Question) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Question

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);
}
Also used : Question(org.survey.model.poll.Question)

Example 3 with 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());
}
Also used : Poll(org.survey.model.poll.Poll) Question(org.survey.model.poll.Question) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Question

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);
}
Also used : Question(org.survey.model.poll.Question)

Aggregations

Question (org.survey.model.poll.Question)4 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 Poll (org.survey.model.poll.Poll)1