1

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.

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
Ahmed Kotb
  • 13
  • 3

3 Answers3

6

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 
jmj
  • 237,923
  • 42
  • 401
  • 438
  • you mean that if method returns for example page called "home"...then it should return "home?faces-redirect=true" or what you mean...i will be thankful if you explain with example – Ahmed Kotb Aug 27 '12 at 10:24
4

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:

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

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.

f_puras
  • 2,521
  • 4
  • 33
  • 38
  • what if i am not using , i mean that link action go to Method in the Server and this Method returns Target Page Name as String. – Ahmed Kotb Aug 27 '12 at 10:22
  • If you return a String (!= null) from an action method, it will be used as an input to all existing navigation rules. If there are no navigation rules, the return value will be ignored. – f_puras Aug 27 '12 at 10:29