Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get JSF 2 url to change after first, not second click

JSF URLs don't seem to change after the first click, only after the 2nd. E.g. when navigating from home.jsf to auction.jsf, the page being displayed is already auction.jsf but the URL in the browser address bar stays at home.jsf, until I click on the Auction link the second time. Why is this happening? Is there a way to disable it, and get the url to display correctly?

like image 378
Herzog Avatar asked Jan 12 '12 18:01

Herzog


1 Answers

You seem to be navigating by POST instead of by GET. You should not perform page-to-page navigation by POST in first place. Replace <h:commandLink> by <h:link>.

So, do not navigate by

<h:form>
    <h:commandLink value="Auction" action="auction" />
</h:form>

but by

<h:link value="Auction" outcome="auction" />

A JSF POST form basically submits to the current URL and any navigation is by default performed by a server-side forward using RequestDispatcher#forward() (if you are well familiar with the basic Servlet API, you know what this means). You could work around with performing a redirect instead

<h:form>
    <h:commandLink value="Auction" action="auction?faces-redirect=true" />
</h:form>

but, as said, this is a work around not a solution.

See also:

  • When should I use h:outputLink instead of h:commandLink?
like image 158
BalusC Avatar answered Nov 03 '22 01:11

BalusC