0

Hi I have an Java EE 7 Application in NetBeans 8.0.2 running on Glassfish 4.01

I use @ManagedBean @SessionScoped as a controller UserController.java

I have an index.xhtml Facelet and an signup.xhtml Facelet

In the index.xhtml Facelet I have

<h:commandButton value="Sign Up" action="#{userController.signUp()}"></h:commandButton>

which calls the function public String signUp() { in the UserController.java

In this function I return return Pages.SIGN_UP_PAGE; which renders the Face let signup.xhtml there I have a Form to fill in your user data such as user Name email and password.

The first thing is that when I return Pages.SIGN_UP_PAGE; the page signup.xhtml gets rendered but in the URL still stands .../faces/index.xhtml

In signup.xhtml I have the

<h:commandButton value="Create User" action="#{userController.createNewUser()}"></h:commandButton>

Then in the public String createNewUser() function I return return Pages.USER_ACTION_OVERVIEW; which renders the page overview.xhtml but then with the URL .../faces/signup.xhtml

which leads to the bigger problem that when I refresh now the page ( the overview page which shows me the data of the new signedUp user ) I send a POST request again to signUp() the same user with the same POST Parameters.

What I need is that if i render the page, that the right URL is displayed ( the on of the page which is rendered ) and that if I refresh that page that not again the old POST request gets send.

Tiny
  • 27,221
  • 105
  • 339
  • 599
Viktor Carlson
  • 989
  • 1
  • 13
  • 36
  • Please have a look at https://stackoverflow.com/questions/15521451/how-to-make-url-reflect-the-current-page-and-not-the-previous-one. I think it is answers your question. – geert3 Dec 16 '14 at 09:05

1 Answers1

0

The JSF perforns a POST based request, that is why your url does not change. The solution is to add faces-redirect parameter to your query sttring like this

public String signUp () {
      //some processing here
      return Pages.SIGNUP_PAGE + "?faces-redirect=true";
 }

This will force a GET redirect to the sign up page after the POST request is completed. As a result, your browser's address bar will show the address of the current page, i. e. the sign up page

akhilless
  • 3,169
  • 19
  • 24