Commit 3c16842b by Tuomas Riihimäki

Pooooooollllll

1 parent 4d3aef6b
......@@ -5,6 +5,7 @@ import javax.ejb.Local;
import fi.insomnia.bortal.model.Poll;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PossibleAnswer;
@Local
public interface PollBeanLocal {
......@@ -14,4 +15,7 @@ public interface PollBeanLocal {
boolean createAnswers(List<PollAnswer> answers);
PossibleAnswer findPossibleAnwerById(int id);
}
......@@ -50,7 +50,7 @@ public class PollAnswer extends GenericEventChild implements Serializable {
return answerText;
}
public void setChoise(PossibleAnswer choice) {
public void setChoice(PossibleAnswer choice) {
this.choice = choice;
}
......
......@@ -41,8 +41,11 @@ public class PollQuestion extends GenericEventChild {
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
public boolean isFreeText()
{
return (answers.size() == 1 && answers.get(0).isText());
}
public void setQuestion(String question) {
this.question = question;
}
......
......@@ -18,7 +18,11 @@
<h:outputText value="#{question.question.question}" />
</h:column>
<h:column>
<h:inputText rendered=""
<h:inputTextarea cols="50" rows="7" value="#{question.textAnswer.answerText}" rendered="#{question.freeText}" />
<h:selectOneRadio converter="#{pollAnswerConverter}" rendered="#{!question.freeText and question.choices eq 1}"
value="#{question.oneSelected}">
<f:selectItems var="ans" itemLabel="#{ans.choice.answer}" value="#{question.answers}" />
</h:selectOneRadio>
</h:column>
</h:dataTable>
......
......@@ -101,6 +101,37 @@ public class PollView extends GenericView {
}
public boolean isFreeText() {
return question.isFreeText();
}
public PollAnswer getTextAnswer() {
if (!isFreeText()) {
throw new RuntimeException("IS not freetext!! !!BUG!!BUG!!");
}
return answers.get(0);
}
public void setOneSelected(PollAnswer ans) {
for (PollAnswer possibleAns : answers) {
if (possibleAns.getChoice().equals(ans.getChoice())) {
possibleAns.setAnswerBoolean(true);
} else {
possibleAns.setAnswerBoolean(false);
}
}
}
public PollAnswer getOneSelected() {
for (PollAnswer possibleAns : answers) {
if (possibleAns.getAnswerBoolean()) {
return possibleAns;
}
}
return null;
}
public PollQuestion getQuestion() {
return question;
}
......
package fi.insomnia.bortal.web.converter;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.NoneScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import fi.insomnia.bortal.beans.PollBeanLocal;
import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.model.PollAnswer;
import fi.insomnia.bortal.model.PossibleAnswer;
import fi.insomnia.bortal.model.Product;
@ManagedBean(name = "pollAnswerConverter")
@NoneScoped()
public class PollAnswerConverter implements Converter {
@EJB
private PollBeanLocal pollbean;
public PollAnswerConverter() {
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
PossibleAnswer possibleAnswer = pollbean.findPossibleAnwerById(Integer.parseInt(value));
PollAnswer ret = new PollAnswer();
ret.setChoice(possibleAnswer);
return ret;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
String ret = null;
if (value instanceof PollAnswer) {
ret = ((PollAnswer) value).getChoice().getId().getId().toString();
}
return ret;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!