我使用JSF創建應用程序。我遇到的問題是,每次刷新頁面時,都會執行commandbuton的動作(ProjectEntityHandlerBean.insertNewProject),導致數據庫中出現多個不需要的條目。我看了相關的線程,但沒有幫助我的情況:如何防止在頁面刷新時執行commandbutton中的操作?
How to avoid re-execution of last form submit action when the page is refreshed?
下面是.xhtml代碼,該代碼bean`s。如果有人能幫忙,我將不勝感激...
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>
你是什麼意思** **後有限的**導航? – TecHunter