JSFを使用してアプリを作成しています。私が抱えている問題は、ページを更新するたびにコマンドボタンのアクションが実行され (ProjectEntityHandlerBean.insertNewProject)、データベースに複数の不要なエントリが作成されることです。関連するスレッドを調べましたが、私の場合は役に立ちませんでした:
ページが更新されたときに最後のフォーム送信アクションの再実行を回避するにはどうすればよいですか?
以下は、Bean のコードである .xhtml コードです。誰かが助けてくれれば、私は感謝します...
public String insertNewProject()
{
System.out.println("Enter insert method");
Project project = new Project();
project.setProjectName(this.projectName);
project.setDescription(this.description);
project.setDuration(this.duration);
ProjectHandler ph = new ProjectHandler();
ph.create(project);
return "viewid?faces-redirect=true";
}
<p:tab title="Insert">
<h:form style="height: 500px; ">
Insert new Project
<h:panelGrid border="2" columns="2" style="height: 200px; width: 383px; ">
<h:outputText value="project name"></h:outputText>
<h:inputText value="#{ProjectEntityHandlerBean.projectName}"></h:inputText>
<h:outputText value="project description"></h:outputText>
<h:inputText value="#{ProjectEntityHandlerBean.description}"></h:inputText>
<h:outputText value="project duration (Months)"></h:outputText>
<h:inputText value="#{ProjectEntityHandlerBean.duration}"></h:inputText>
</h:panelGrid>
<h:commandButton value="Submit" action="#{ProjectEntityHandlerBean.insertNewProject}"></h:commandButton>
</h:form>
</p:tab>