How do I implement a navigation button in JSF 2.0 that doesn't do any validation on anything on the current page?
I want to implement a navigation button that takes the user to another page. I have no desire or need for any checks, nor for an updatable model, etc. I have implemented this as a client side redirect (note that I am using Primefaces 3.2).
It works ... but is this the best way to do it?
Moving from "onePage.xhtml" to "anotherPage.xhtml"
onePage.xhtml:
...
<p:commandButton value="Navigate to Another Page"
process="@this"/>
action="anotherPage?faces-redirect=true"
...
Note that I tried using immediate = "true", but the Apply Request Values phase is still running, which results in an NPE for me in the getter in my managed bean (as I no longer have the data that my getter needs).
source to share
Just use <h:button>
or <p:button>
. It sends a normal GET request. There is really no need for a POST-Redirect-GET request if it just translates pages to page.
<h:button value="Navigate to Another Page" outcome="anotherPage" />
For the PrimeFaces look'n'feel element, simply replace h:
with p:
. Please note that this component is not required <h:form>
. The link equivalent is <h:link>
(for which there is no PrimeFaces equivalent, nothing needs to be restyled anyway).
See also:
source to share