Commit 570f8f38 by Juho Juopperi

Merge branch 'master' of dev.intra.insomnia.fi:/data/bortal

2 parents b6075f7e 54ec9825
......@@ -33,6 +33,10 @@ public abstract class GenericEventChild implements EventChildInterface {
super();
}
public GenericEventChild(EventPk eventPk) {
id = eventPk;
}
@Override
public final boolean equals(Object object) {
......
package fi.insomnia.bortal.model;
import fi.insomnia.bortal.model.GenericEntity;
import static javax.persistence.TemporalType.TIMESTAMP;
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import javax.persistence.*;
import static javax.persistence.TemporalType.TIMESTAMP;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
/**
* Entity implementation class for Entity: Poll
......@@ -73,4 +76,12 @@ public class Poll extends GenericEventChild implements Serializable {
this.description = description;
}
public void setQuestions(List<PollQuestion> questions) {
this.questions = questions;
}
public List<PollQuestion> getQuestions() {
return questions;
}
}
......@@ -34,12 +34,17 @@ public class PollAnswer extends GenericEventChild implements Serializable {
this.answerText = answerText;
}
public PollAnswer(PollQuestion q)
{
super(new EventPk(q.getId().getId()));
}
public String getAnswerText() {
return answerText;
}
public void setChoice(PossibleAnswer choise) {
this.choice = choise;
public void setChoise(PossibleAnswer choice) {
this.choice = choice;
}
public PossibleAnswer getChoice() {
......
package fi.insomnia.bortal.view;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.view.helpers.PollWrapper;
@ManagedBean(name = "pollView")
@SessionScoped
public class PollView extends GenericView {
@EJB
private PollBeanLocal pollBean;
private PollWrapper pollwrapper;
private ListDataModel<Poll> polls;
public void initPollList() {
polls = new ListDataModel<Poll>(pollBean.findPolls());
}
public String beginPoll() {
pollwrapper = new PollWrapper(polls.getRowData());
}
}
package fi.insomnia.bortal.view.helpers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import javax.faces.model.ListDataModel;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PollQuestion;
import fi.insomnia.bortal.view.helpers.PollWrapper.QuestionWrapper;
public class PollWrapper {
HashMap<Integer, List<QuestionWrapper>> pages;
public PollWrapper(Poll poll) {
pages = new HashMap<Integer, List<QuestionWrapper>>();
for (PollQuestion q : poll.getQuestions()) {
if (!pages.containsKey(q.getPage())) {
pages.put(q.getPage(), new LinkedList<QuestionWrapper>());
}
pages.get(q.getPage()).add(new QuestionWrapper(q));
}
}
public class QuestionWrapper {
private PollQuestion question;
private PollAnswer answer;
public QuestionWrapper(PollQuestion q) {
question = q;
answer = new PollAnswer(q);
}
public PollQuestion getQuestion() {
return question;
}
public void setQuestion(PollQuestion question) {
this.question = question;
}
public PollAnswer getAnswer() {
return answer;
}
public void setAnswer(PollAnswer answer) {
this.answer = answer;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!