PrimeFaces navigation problem JSF 2.0


      Click here to attend Spring Framework 4.x and certification course with a discount

While using PrimeFaces p:commandButton component, you may have some problems regarding the JSF 2.0 xml-less navigation. Normally, using JSF 2.0 technology, developer can navigate between views by only returning  a string view-id like the following example (there is no need to define rules inside faces-config.xml file);

inside UserBean;

public String login() {
  return "success"; //view-id
}

 

<h:commandButton  action="#{userBean.login}" value="Login" style="margin-left:0px" />

or  directly by setting

<h:commandButton action="success.xhtml" value="Submit" />

However, as the document of PrimeFaces (FAQ) indicates, http://primefaces.org/faq.html

PrimeFaces does not support forward based navigations within an ajax request, you need to do redirect instead or set ajax to false.

so that p:commandButton could be used like the following way if you need to have AJAX functionality with it;

inside UserBean;

public String login() {
  return "success.xhtml?faces-redirect=true"; //view-id

 

<p:commandButton ajax="true" action="#{userBean.login}" value="Login" update="panel"
style="margin-left:0px" />


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s