2

When I want to "delete a plane" from my jsf page, if successful the plane deletes, and I do a redirect to the page and show an alert telling the user the plane was succesfully deleted. However, the values the user entered in the h:inputText are still there, they dont empty.

JSF Page:

<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 code:

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

Any ideas on why the fields dont empty after redirect?

CJR
  • 3,174
  • 6
  • 34
  • 78

1 Answers1

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.

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
  • Yes, It is a **@ViewScoped** bean. Should I change it to **@RequestScoped** or implement manual reset? Which one should I choose? The bean I use for getting a list of airplanes from my backend part- – CJR Nov 26 '16 at 18:41
  • It is hard to say as it depends whether the content of your page would at some point need ajax processing. In that case you would most likely have to stay with the **ViewScoped**. On the other hand if that form content in your post is the only content that is expected on that page then i would go for **RequestScoped** as it would be more natural to configure it that way. Hope that helps. – Maciej Kowalski Nov 26 '16 at 18:48
  • Here is a link to the post which explains in a bit more details of the difference - http://stackoverflow.com/questions/6025998/difference-between-view-and-request-scope-in-managed-beans – Maciej Kowalski Nov 26 '16 at 18:54
  • Thank you, very helpful! – CJR Nov 26 '16 at 19:11