This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes when using commandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "when using commandButton" Watch "when using commandButton" New topic
Author

when using commandButton

Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
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?


Jys<br /><a href="http://jy-s.com" target="_blank" rel="nofollow">http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.
Kevin Galligan
Ranch Hand

Joined: Aug 10, 2005
Posts: 70
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

Joined: May 08, 2005
Posts: 87
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

Joined: Aug 10, 2005
Posts: 70
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

Joined: Aug 10, 2005
Posts: 70
Man, tough morning. Flip action and value from before...

<h:commandButton
action="somePage"
value="Back">
</h:commandButton>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when using commandButton
 
Similar Threads
h:commandButton problem
Command button click issue
Button action depending on checkbox selection.
Ajax & Myfaces problem - pages reloads with commandButton.
commandButton in rich:modalPanel issues