• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when using commandButton

 
Jolie Lee
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried history.go(-1) and location.href when using commandButton but both doens't work.
i useonclick on the commandButton for these javascript.
how should i go about it?
 
Kevin Galligan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jolie Lee
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Kevin Galligan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

<h:commandButton
value="somePage"
action="Back">
</h:commandButton>

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)...

http://www.coderanch.com/t/210875/JSF/java/Simple-pattern

If you are navigating a database hierarchy, you either need to abandon the browser's back button navigation, or use something other than JSF.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man, tough morning. Flip action and value from before...

<h:commandButton
action="somePage"
value="Back">
</h:commandButton>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic