i tried history.go(-1) and location.href when using commandButton...
Tried to do what? Force the browser back?
Trying my very best to learn java...
Admirable. My only advice would be that trying to control the browser navigation for the user isn't going to go well. I'd especially advise against trying to use the back button in any way with JSF.
Are you trying to set the location in the onclick of the command button? I think this would be the opposite of what JSF is trying to do. Please post some code.
I'd also suggest if you're trying to learn how to heavily script your pages that you start with plain jsp so you understand how this stuff works. JSF does a lot for you, but you're on your own if you step out of the sandbox (like trying to do redirect the browser in a commandButton's onclick).
Joined: May 08, 2005
hi, actually what i intended to do is to have a "Back" button for user so that they can go back to the page they come from..
so if commandButton is not the right way, how can i have a Back button then?
i tried to post my code but it does not allows me when i haveonclick, even when i post it in the "[code]" tag..
Joined: Aug 10, 2005
commandButton is fine. Trying to make the browser go 'Back' as if the user clicked the Back button isn't the best way to go. Its a little hard to explain, but many web applications have trouble with the back button, and JSF applications are no exception to that.
If you want a 'Back' button, I'd suggest just using a commandButton with a string that returns the user to wherever they should go...
Set up 'somePage' in your faces-config.xml navigation to go somewhere specifc. If the user may have come from different places to your current page, you'll have to pass in and retain a source variable of some type. I generally avoid this type of thing by having absolute navigation on the outside of the page (top level links on the top or left), and having a hierarchical navigation on the page somewhere.
For example, if the user drilled down to this page, show the hierarchy at the top, complete with links to the higher levels.
You can retain a history of the pages that the user has been to, and provide for 'Back' buttons, but I think this will be error prone and ultimately not required (but I don't know what you're building, so maybe you really do need it)?
In some instances of navigation I have issue with the recommended JSF approach (see my favorite thread. I'm about to add to it)...