Here is a code I use :
request.jsf
<h:form>
<!-- form inputs ... -->
<h:commandButton id="btnStart" value="START" action="#{bean.handleForm}">
<f:ajax execute="@form" render="message" />
</h:commandButton>
</h:form>
When I click btnStart button, the form is submited and correctly processed by my bean. Unfortunately, the browser url bar still displays http://myhost.com/request.jsf whereas the content displays the outcome returned by #{bean.handleForm}.
How can I update the url bar correctly ?
That’s because your form is submitting to the current URL and JSF just changes the resource of the response. If you’d like to change the URL to be the one of the new resource, then you need to tell the webbrowser to send a new request on that. You can do that by performing a redirect. In JSF 2 it’s a matter of adding
faces-redirect=trueas query string to the outcome.Alternatively, if it’s really a non-idempotent request, then I’d stick to the same page and just conditionally display the results in the very same page, if necessary by an include. Your action method can then return
nullorvoid.