public void createPieChart(Question question) {
    pieChart = new PieChartModel();

    for (Answer answer : question.getAnswers()) {
      pieChart.set(answer.getAnswer(), answer.getResults().size());
    }

    pieChart.setShowDataLabels(true);
    pieChart.setTitle(question.getTitle());
    pieChart.setLegendPosition("w");
  }
  public List<Question> getAllQuestions() {
    questions = new ArrayList<Question>();
    List<Question> aux = questionService.findAll();

    Date now = new Date();
    for (Question question : aux) {
      if (question.getExpirationDate().after(now)) {
        questions.add(question);
      }
    }
    return questions;
  }
  public void insertVote(Answer answer) {
    Result result = new Result();
    result.setQuestion(question);
    result.setAnswer(answer);
    result.setDateVote(new Date());
    createCookie(String.valueOf(question.getId()), String.valueOf(question.getId()), 86400);
    resultService.save(result);

    createPieChart(question);
    setShowPanelAnswers(Boolean.FALSE);
    setShowPanelResult(Boolean.TRUE);

    jsfMessage.sendInfoMessageToUser("Thanks for you vote!");
  }
  public void showAnswers(Question question) {
    if (validateVote(question.getId())) {
      setQuestion(question);
      setAnswers(question.getAnswers());
      setSubtitle(question.getQuestion());
      setShowPanelQuestions(Boolean.FALSE);
      setShowPanelAnswers(Boolean.TRUE);
    } else {
      createPieChart(question);

      setShowPanelQuestions(Boolean.FALSE);
      jsfMessage.sendErrorMessageToUser("You already participated in this poll!");
      setShowPanelResult(Boolean.TRUE);
    }
  }