提交和重定向后输入字段没有清空?

时间:2016-11-26 17:23:01

标签: java html jsf

当我想从我的jsf页面“删除一架飞机”时,如果飞机成功删除,我会重定向到该页面并显示警告,告诉用户飞机已成功删除。但是,用户在h:inputText中输入的值仍然存在,它们不会为空。

JSF页面

<h:form>
    <h:panelGrid columns="3" class="table">
        <h:outputLabel value="Plane ID" />
        <h:inputText  value="#{listAirplaneBB.airPlaneId}"/>
        <h:commandButton value="Delete" 
            class="btn btn-primary"
            action="#{addAirplaneCtrl.deleteAirplane}" />
    </h:panelGrid>
</h:form>

Bean代码:

public String deleteAirplane(){
    //delete the plane
    return private/user?faces-redirect=true;
}

有关为什么字段在重定向后不会清空的任何想法?

1 个答案:

答案 0 :(得分:2)

Maybe your listAirplaneBB is a @ViewScoped bean (cant tell by your example).
In that case you have to clean any particular fields manually before redirecting as JSF keeps alive that bean while the target page has not changed.