Ahmed Kotb
Ahmed Kotb

Reputation: 13

Previous Page URL JSF

I'm working with a JSF application and I'm seeing the URL that appears in the browser's navigation bar is always for the page I just left, rather than the page I'm on.

Upvotes: 1

Views: 2025

Answers (3)

BalusC
BalusC

Reputation: 1108632

That will happen if you're using POST for navigation by e.g. commandlinks/commandbuttons. If it's pure page-to-page navigation and you actually don't need to submit anything to the server, then you've a bigger problem. You will indeed get exactly this nasty "side effect" and your links will not be bookmarkable nor searchbot-crawlable. PRG (Post-Redirect-Get), as suggested by other answers, will indeed solve the bookmarkability ("one URL behind") problem, but it surely won't solve the inability of searchbots to crawl/index the pages.

Just don't use POST for plain page-to-page navigation in first place. Use GET for that. Use <h:link> instead of <h:commandLink> and so on. In code, replace all

<h:form>
    <h:commandLink value="Next page" action="nextpage" />
</h:form>

by

<h:link value="Next page" outcome="nextpage" />

See also:

Upvotes: 4

f_puras
f_puras

Reputation: 2505

By default, JSF performs POST operations directed to the original page's URL. If you use a <navigation-rule>, you can specify <redirect/> to let the browser perform an additional request, so the target page's URL will appear in the navigation bar.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240860

It is because you are forwarded(not redirected) to another page from server, To redirect you need to set the following param with your return

?faces-redirect=true 

Upvotes: 6

Related Questions