views:

286

answers:

2
+1  Q: 

JSF Back Button

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

Thanks.

+1  A: 

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
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
@Brian: Press `Ask Question` button if you stucks. Post an SSCCE if you can.
BalusC
Nevermind, I got it. Needed to set "type=button" as well...
Brian Knoblauch