3

How do I make a link which navigates the user back one page (i.e. same as clicking browser back)?

Thanks.

DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

6

To the point: just remember the request URL or the JSF viewId of the previous page so that you can use it in the href or value of the output/commandlink. There are several ways to achieve it, depending on how you're actually navigating through the pages and how "jsfish" you want to achieve it. You could pass it as a request parameter by f:param in h:outputLink, or you could set it as a bean property by f:setPropertyActionListener in h:commandLink, or you could create a PhaseListener which remembers the viewId and make use of navigation cases, or you could grab the -much less reliable- JavaScript history.go() function.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I'm missing something here. Trying to implement the history.go() method of going back (because I have to go back to non-JSF pages too), but the javascript doesn't run. immediate=true and onclick of history.go(-1). The onclick javascript never gets called, the page refreshes instead. – Brian Knoblauch Sep 14 '10 at 17:41
  • @Brian: Press `Ask Question` button if you stucks. Post an SSCCE if you can. – BalusC Sep 14 '10 at 17:59
  • Nevermind, I got it. Needed to set "type=button" as well... – Brian Knoblauch Sep 14 '10 at 18:11
  • BalusC: do you think you can elaborate the use of `PhaseListener`? Maybe add a bit more code into it? – Thang Pham May 21 '12 at 19:26