my problem is the following.
I would like to make a questionnaire with JSF and I want to increment a counter all along the pages. May be the best way to do it is to also set an ajax event.
Here is the index.xhtml :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body>
Question :
<h:form id="questionForm">
<h:outputLabel value="#{questionBean.questions[0].askedQuestion}">
</h:outputLabel>
<h:selectOneRadio>
<f:selectItems value="#{questionBean.questions[0].proposals}"
var="proposal" itemValue="#{proposal}" />
</h:selectOneRadio>
</h:form>
</h:body>
</html>
As you notice, the value for the first question is the first element of a list which is created. I would like to set a counter in order to go the the n+1 question at each click.
Here is the questionBean :
package trainforjava.question;
import java.util.Collections;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
@Controller
public class QuestionBean {
static Logger log = Logger.getLogger(QuestionBean.class.getName());
private List<Question> questions;
private int counter = 0;
public QuestionBean() {
QuestionCreator creator = new QuestionCreator();
questions = creator.createQuestions();
System.out.println(questions);
Collections.shuffle(questions);
System.out.println(questions);
log.info(questions);
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public int increment() {
counter++;
return counter;
}
}
I would like to refer the method increment() as a parameter of the page, and then increment it all along the questionnaire. I tried to use but it's lonly for backing bean.
Someone can help me on this ?
Thank u