0

I am using a <p:commandButton> for navigation and set ajax="false", however the addressbar won't update to match the target page as defined in action-attribute. It still shows the address of the initial page with the <p:commandButton>.
I could swear it was not always like that. Is this behaviour normal?
How could I fix this still using <p:commandButton> for navigation?

my code:

<p:commandButton value="speichern" action="secondPage" ajax="false"/>
Lester
  • 1,830
  • 1
  • 27
  • 44

1 Answers1

1

Yes, this is normal behavior if you fire a POST request. The <form action> as generated by <h:form> defaults to the current URL (rightclick, View Source in browser to see it yourself). Exactly this URL get reflected in browser address bar. If you want to change it after POST, you need to send a redirect afterwards. A redirect basically instructs the client to send a new GET request on the given URL. This will get reflected in browser address bar. This can be done by adding faces-redirect=true query string parameter to the outcome value.

<p:commandButton value="speichern" action="secondPage?faces-redirect=true" ajax="false"/>

However, using POST for navigation is bad for UX and SEO. Just use GET in first place.

<p:button value="speichern" outcome="secondPage"/>

See also:

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