Navigating to another page in AJAX calls
PrimeFaces' users often ask "Why don't navigations work with PrimeFaces CommandButton
and CommandLink
?", "How can we navigate to any page on a node click in a Tree
?", or "How can we change the view when a row in a DataTable
is double-clicked?". These are questions that are mainly related to JSF rather than PrimeFaces, but we will give answers to these questions in this book due to their importance.
In this recipe, we will show a programmatic navigation with JSF NavigationHandler
as well as a declarative way to do a cross-page navigation in AJAX calls.
How to do it...
All three
questions mentioned above have the same nature. JSF and PrimeFaces do not support a forward-based navigation within an AJAX request. We need to do a redirect instead or set the ajax
attribute in the command components to false
.
The showcase application of this book has a Tree
component with nodes representing the recipes. A click on a node redirects the user to a well-defined...