How to call a .xhtml page on the click of a p:commandButton

Posted on 2014-03-24
Medium Priority
Last Modified: 2014-04-21
I have a simple p:commandButton as follows...

<p:commandButton value="Next" type="button" />

I have a next.html page. I want to display the contents of the next.html on the
browser when clicked the "Next" button. How should I do that in JSF/PrimeFaces?
Question by:prain
  • 4
  • 2
LVL 12

Assisted Solution

by:Gibu George
Gibu George earned 1000 total points
ID: 39952862
You can either add an actionlistener if you want to send the request to server and do some pre requisite operations before going to the next.html, or you can add a javascript function on the onclick and use the window.href.location to be changed to next.html

Author Comment

ID: 39953329
In a table I have this component....

<p:commandButton value="Next" type="button" actionListener="#{personnel.resignationContinuation()}" />

And the listener is shown below...

Yet, the continuationPage.xhtml page is not getting loaded.

public void resignationContinuation()
   FacesContext context = FacesContext.getCurrentInstance();
                ExternalContext externalContext =
   externalContext.redirect(externalContext.getRequestContextPath() +
            catch (IOException e) {
LVL 12

Expert Comment

by:Gibu George
ID: 39955224
Can you try logging the exception instead of an empty catch block or do e.printStackTrace(), and let me know if any exception is occuring
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Accepted Solution

prain earned 0 total points
ID: 39955939
Ok. I am working on JBoss Development Studio (just FYI). This is a actually a mistery for me. Just for testing purposes I just added a System.out.println() after removing everything from the resignationContinuation() event handler. I was expecting to see the print line coming up on the JBoss Console (This is the way I test out other event handlers). For some reason the p:commandButton (at least this one) does not fire the actionListener.  Here is a skeletion of my current code....
<p:panel style="text-align:center">
  <p:commandButton value="Cancel" type="button" style="width:80px" />
  <p:commandButton value="Update" type="button"  style="width:80px" />
  <p:commandButton id="cmdBtnNext"
                                       type="submit" />

And Here is the bean code....
public class ResignationContinuation extends PageBean
  public ResignationContinuation() {
            // TODO Auto-generated constructor stub

  public void init() throws Exception {
            try {
            }catch(Exception e) {

public void show()
          System.out.println("Reached show()");
          catch(Exception e)

No stack trace or no print line. Very strange......

Author Comment

ID: 39956428
Just for the heck of it, I seperated these buttons into a seperate form. Boom, it works!!!!!!!!!!!!!!!!!!. I do not know how and why if does not work when these componets are in the same form with the other components.

Author Closing Comment

ID: 40012201
Good pointer

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question