I need to build an app of Quiz that contains questions (each question has 2 possible answers) I stored some questions in database. once you select an answer and click "Next", you'll see the next question. I have a bean that represent each question, it's called Item, and has the attributes: question, ansA, ansB; and I have a bean:
@ManagedBean
@ViewScoped
public class Bean {
private List<Item> items = new ArrayList<Item>();
private List<Item> helper = new ArrayList<Item>();
private String myValue;
int indexHelp = 0;
public String next() {
items.clear();
items.add(helper.get(indexHelp));
indexHelp++;
System.out.println("chose: " + myValue);
return "ok";
}
the list helper is stored already with the questions from the database
the jsf file:
<h:form>
<h:dataTable value="#{bean.items}" var="item">
<h:selectOneRadio value="#{bean.myValue}">
<h:column>
<f:selectItem itemLabel="#{item.question}" />
</h:column>
<h:column>
<f:selectItem itemValue="1" itemLabel="#{item.ansA}" />
</h:column>
<h:column>
<f:selectItem itemValue="2" itemLabel="#{item.ansB}" />
</h:column>
</h:selectOneRadio>
</h:dataTable>
<h:commandButton value="Next" action="#{bean.next}" />
</h:form>
the problem is that when I run the project, it doesn't show the radio buttons, the question or the answers. Thank you!!
Here's something that matches your description:
And your JSF page goes like this:
You probably want to add a "evaluate" button that you show when there's no question left or something (since you need to do something with the
alreadyAnswered
list of questions).