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 h: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 "h:commandButton" Watch "h:commandButton" New topic


raghu namala

Joined: Apr 12, 2012
Posts: 4

i created a page with h:commandButton..i dont want my page to be navigated to new page when this button is clicked.. i saw some posts on java ranch. i tried to using history.back()..

any help appreciated..

thanks in advance
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
If you have action="#{bean.testAction}" and

is this what you mean? I'm not at all sure what history.back has to do with anything.

raghu namala

Joined: Apr 12, 2012
Posts: 4
hey thanks for the reply Brendan,

i tried that it dint work...

i m using jsf 2.0 facelets...i have tree menu on the left pane... when a click on the tree menu item will display the contents of center pane using ajax(using jquery for it..) the contentPane has commandButtons.. when i click this button it should invoke a method on jsf bean..and it should stay on the same page...and also is it possible to get the output of the string to change the color of commandButton???

Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
Can you post your code, it's not easy to follow without it.
raghu namala

Joined: Apr 12, 2012
Posts: 4

login page:
<div id="header"></div>
<div id="footer"></div>
<div id="leftNav>


<div id="centerPane">

when click on menu1 fetch myPage1.xhtml and place it in centerPane div...

now my centerPane div has

<div id="centerPane">
<div id="status" ></div>
<h:commandButton value="start" action="#{mybean.myMethod1}"actionListener="#{mybean.myMethod2}"/>


public String myMethod1(){"this line is printing from the navigateMe method: ");
return null;

how click on start commandButton displaying new page(i.e.myPage.xhtml)....[BUT THE VIEW SHOULD BE SAME WITH THE HEADER, FOOTER, LEFT AND CONTENT PANES...)
Prateek Kumar Singh

Joined: Jan 21, 2011
Posts: 29

If you have action="#{managedBean.testAction}"
then you can use the code to return any page

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950


Is not true. In JSF1, "pageName" would be the name of a Navigation rule. In JSF2, it can be the name of a navigation rule OR it can be a JSF context-relative URL. ".xhtml" is normally the extension of the resource, not of the URL, and resource paths and URLs are 2 different things that merely happen to resemble each other. You can, in fact, code

Although there's no practical benefit to doing so, since JSF already assumes that it's a JSF URL.

And of course, once again, coding a user-defined login is essentially telling hackers to invade your site and take over.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: h:commandButton
Similar Threads
Need help with passing data between pages through h:commandButton
question on a4j:commandButton
how to dynamically set the action attribute
How to Open JSF Page in Separate Browser Window
Ajax listener method is not fire for other(except first) component