This example application can be run here. It illustrates the following:
The numberquiz web application is defined by the following:
Java classes (Source Packages/com/corejsf/):
JSF pages (Web Pages/):
Properties files (Source Packages/com/corejsf/):
Configuration files (Web Pages/WEB-INF/:
Text.
To manage application strings with internationalization, you need to
The bundle for the numberquiz application consists of the two files
The bundle is declared in the faces-config.xml file.
<title>#{msgs.title}</title>
private @Inject Conversation conversation;The instance variable will be automatically initialized with a Conversation object when the bean is constructed.
@Named @ConversationScoped public class QuizBean implements Serializable { @Inject Conversation conversation; ... public void setAnswer(String newValue) { try { if (currentIndex == 0) conversation.begin(); int answer = Integer.parseInt(newValue.trim()); if (getCurrent().getSolution() == answer) score++; currentIndex = (currentIndex + 1) % problems.size(); if (currentIndex == 0) conversation.end(); } catch (NumberFormatException ex) { } } }Now each quiz keeps its own score and current index. When the quiz is over, the conversation ends.