1

I have a small JSF (latest) application. This kind of navigation works fine

<p:commandButton value="New user" action="#{loginView.createUser()}"/>

with

    public String createUser() {
    return "newUser" + SessionUtils.REDIRECT_URL_SUFFIX;
  }

However, when trying the following method, it gives me a 404 error:

<p:commandButton value="New user" action="#{loginView.createUser()}"/>

with

public void createUser() {
FacesContext.getCurrentInstance().getExternalContext().redirect("newUser.xhtml" + SessionUtils.REDIRECT_URL_SUFFIX);
}

Any suggestions?

I should add that the above method only works when navigating from the first page to the second. It stops working after that... The first one works fine on any page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

1

Try:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/" + "newUser.xhtml" + SessionUtils.REDIRECT_URL_SUFFIX);
Ermal
  • 441
  • 5
  • 19