私は単純なJSFアプリケーションを作成しました。これはユーザーのための質問と、可能な回答のセットをラジオボタンとして提示します。JSF quizzアプリケーションのナビゲーション
ユーザーが回答を選択して送信すると、Beanは質問を更新して同じページを返し、新しい質問が表示されます。最後の質問に達すると、結果とともに終了ページが返されます。
これはうまくいきますが、ユーザーがブラウザの戻るボタンをクリックしてフォームを再送信すると問題が発生します。これはbean.currentQuestionを増やし、ロジックを破壊します。
//index.xhtml
<h:form>
<div class="questionNumberDiv" id ="questionNumberDiv">
<h:outputLabel value="Question #{test.currentQuestion + 1}" for="questionLabel"/>
</div>
<br/>
<div class="questionDiv" id="questionDiv">
<h:outputLabel id ="questionLabel" value="#{test.questions[test.currentQuestion].question}"/>
</div>
<br/>
<div class="questionDiv" id="possibleAnswersDiv">
<h:selectOneRadio requiredMessage="Please, select one answer!" id="radio" layout="pageDirection" value="#{test.currentAnswer}" required="true">
<f:selectItems value="#{test.questions[test.currentQuestion].possibleAnswers}" var="y"
itemLabel="#{y}" itemValue="#{y}" />
</h:selectOneRadio>
</div>
<br/>
<h:panelGrid columns="2" styleClass="requiredMessage">
<h:commandButton value="next question" action ="#{test.processAnswer}" />
<h:message for="radio"/>
</h:panelGrid>
</h:form>
</h:body>
ビーン方法...というページフリップのない質問を更新しアヤックスが、今はフィニッシュページを提示する方法を知らない:
私はFを試してみましたユーザーが次の質問にヒットしたとき:
public String processAnswer()
{
Question q = questions.get(currentQuestion);
currentQuestion++;
userAnswers.add(currentAnswer);
if (currentQuestion == questions.size())
{
this.processResults();
return "finish";
}
else
{
return "index";
}
}
どうすればこの問題を解決できますか?
ありがとうございます!私はあなたのロジックについて多くを知らないにも関わらず
使用しているコードは何ですか?あなたはf:ajaxで何をしようとしましたか?あなたの論理はどのように壊れていますか – Deco
コードを投稿してください。 – Robin
ちょうどそれを明確にする:アプリケーションがうまくいく、問題は、ユーザーがブラウザの戻るボタンを押して同じ質問を再回答(再提出)した場合に起こることです...これを解決するために私はf:ajaxに新しい質問を読み込み、それは動作しますが、私は 'finish'ページを返す方法を知らない...ありがとう! – Fernando