JSF 2.2表单提交,重新加载页面=重新提交?

时间:2013-11-07 23:25:05

标签: forms jsf jsf-2 facelets

所以我有一个JSF应用程序。如果我提交表单,则在刷新页面时会重新提交。当然,我不希望这样。

的index.xhtml:

[...]
    <h:form >
        <h:outputText value="Form"/><br/>
        <h:inputText label="first" value="#{example.newExample.firstWord}" autocomplete="off"></h:inputText>
         <h:commandButton value="click" actionListener="#{example.NewExample()}">        

         </h:commandButton>

    </h:form>
[...]

运行的方法:

  public void NewExample(){
    pfDB.InsertNewExample(NewExample);
    NewExample.setFirstWord(null);
    NewExample.setSecondWord(null);
}

所以每次我提交表单后刷新index.xhtml,NewExample()都会运行。

1 个答案:

答案 0 :(得分:2)

确实是重新提交表格的问题。但浏览器(歌剧)没有显示警报。

我通过添加

修复了它
  FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");

在我的功能中

相关问题