Commit bd7bc9b5 by Tuomas Riihimäki

asdasd

1 parent ff81526e
......@@ -41,8 +41,9 @@ public class PollAnswer extends GenericEventChild implements Serializable {
super();
}
public PollAnswer(PollQuestion q) {
super(new EventPk(q.getId().getId()));
public PollAnswer(PossibleAnswer a) {
super(new EventPk(a.getId().getId()));
this.choice = a;
}
public String getAnswerText() {
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.eventorg.list" />
<ui:define name="content">
<h:form id="answerForm">
<h:dataTable border="1" id="questions" value="#{pollView.currentPage}" var="question">
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['poll.name']}" />
</f:facet>
<h:outputText value="#{question.question.question}" />
</h:column>
<h:column>
<h:inputText rendered=""
</h:column>
</h:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
<ui:composition template="/layout/#{sessionHandler.layout}/template.xhtml">
<ui:param name="thispage" value="page.eventorg.list" />
<ui:define name="content">
#{pollView.initPollList()}
<h:form>
<h:dataTable border="1" id="maps" value="#{pollView.polls}" var="poll">
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['poll.name']}" />
</f:facet>
<h:outputText value="#{poll.name}" />
</h:column>
<h:column>
<h:commandButton action="#{pollView.beginPoll()}" value="#{i18n['poll.answer']}" />
</h:column>
</h:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
package fi.insomnia.bortal.view;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
......@@ -7,7 +12,9 @@ import javax.faces.model.ListDataModel;
import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.view.helpers.PollWrapper;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PollQuestion;
import fi.insomnia.bortal.model.PossibleAnswer;
@ManagedBean(name = "pollView")
@SessionScoped
......@@ -16,22 +23,100 @@ public class PollView extends GenericView {
@EJB
private PollBeanLocal pollBean;
private PollWrapper pollwrapper;
private ListDataModel<Poll> polls;
private HashMap<Integer, List<QuestionWrapper>> pages;
private Integer thisPage = 1;
public void initPollList() {
polls = new ListDataModel<Poll>(pollBean.findPolls());
setPolls(new ListDataModel<Poll>(pollBean.findPolls()));
}
public String nextPage() {
++thisPage;
return null;
}
public List<QuestionWrapper> getCurrentPage() {
return pages.get(thisPage);
}
public String beginPoll() {
pollwrapper = new PollWrapper(polls.getRowData());
return "showPoll";
thisPage = 1;
Poll poll = polls.getRowData();
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));
}
return "/poll/answerToPoll";
}
public String savePoll() {
if (pollwrapper.validate(this)) {
pollBean.createAnswers(pollwrapper.getAnswers());
if (validate(this)) {
pollBean.createAnswers(createAnswers());
}
return "thankYou";
}
public void setPolls(ListDataModel<Poll> polls) {
this.polls = polls;
}
public ListDataModel<Poll> getPolls() {
return polls;
}
private List<PollAnswer> createAnswers() {
ArrayList<PollAnswer> ret = new ArrayList<PollAnswer>();
for (List<QuestionWrapper> qw : pages.values()) {
for (QuestionWrapper wrapper : qw) {
ret.addAll(wrapper.getAnswers());
}
}
return ret;
}
public boolean validate(PollView pollView) {
boolean ret = true;
return ret;
}
public class QuestionWrapper {
private PollQuestion question;
private ArrayList<PollAnswer> answers;
public QuestionWrapper(PollQuestion q) {
question = q;
answers = new ArrayList<PollAnswer>();
for (PossibleAnswer possible : q.getAnswers()) {
answers.add(new PollAnswer(possible));
}
}
public PollQuestion getQuestion() {
return question;
}
public void setQuestion(PollQuestion question) {
this.question = question;
}
public void setAnswers(ArrayList<PollAnswer> answers) {
this.answers = answers;
}
public ArrayList<PollAnswer> getAnswers() {
return answers;
}
}
}
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.PollView;
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;
}
}
public List<PollAnswer> getAnswers() {
ArrayList<PollAnswer> ret = new ArrayList<PollAnswer>();
for (List<QuestionWrapper> qw : pages.values()) {
for (QuestionWrapper wrapper : qw) {
ret.add(wrapper.getAnswer());
}
}
return ret;
}
public boolean validate(PollView pollView) {
boolean ret = true;
return ret;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!