gaffcz
gaffcz

Reputation: 3479

Refresh page (browser button) leads to save item to database again

Situation:

How can I prevent that behaviour?

Upvotes: 0

Views: 1160

Answers (1)

BalusC
BalusC

Reputation: 1108577

Two ways:

  1. Use ajax to execute the action (this doesn't generate browser history).

    <h:commandButton ...>
        <f:ajax execute="@form" render="@form" />
    </h:commandButton>
    
  2. Send a redirect after post (known as POST-Redirect-GET pattern).

    public String save() {
        // ...
        return "sameview?faces-redirect=true";
    }
    

Upvotes: 2

Related Questions