Solved

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

Posted on 2014-03-24
6
369 Views
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?
0
Comment
Question by:prain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 12

Assisted Solution

by:Gibu George
Gibu George earned 250 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
0
 

Author Comment

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


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


And the listener is shown below...

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

public void resignationContinuation()
{
 try
  {
   FacesContext context = FacesContext.getCurrentInstance();
                ExternalContext externalContext =
   context.getExternalContext();
      
   externalContext.redirect(externalContext.getRequestContextPath() +
"/subpages/continuationPage.jsf");
            }
            catch (IOException e) {
                               }
      }
0
 
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
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Accepted Solution

by:
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"
                                       value="Next"
                                       actionListener="#{resignationContinuation.show}"
                                       style="width:80px"
                                       type="submit" />
</p:panel>

And Here is the bean code....
@ManagedBean(name="resignationContinuation")
@ViewScoped
public class ResignationContinuation extends PageBean
{
  public ResignationContinuation() {
            // TODO Auto-generated constructor stub
  }

  @PostConstruct
  public void init() throws Exception {
            try {
                   super.init();
            }catch(Exception e) {
   }
}

public void show()
{
  try{
          System.out.println("Reached show()");
          catch(Exception e)
         {
              e.printStackTrace();
          }
     }
}


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

Author Comment

by:prain
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.
0
 

Author Closing Comment

by:prain
ID: 40012201
Good pointer
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.

705 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