BestPractices
BestPractices

Reputation: 12876

How to implement a navigation button in JSF 2.0 that doesnt do any validations of 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 validations to run nor for the model to be updated, etc. I have implemented this as an ajaxified client-side redirect (note, I am using Primefaces 3.2).

It works-- but is this the best way to do this?

Navigating from the "onePage.xhtml" to the "anotherPage.xhtml"

onePage.xhtml:
...
<p:commandButton value="Navigate to Another Page" 
                 process="@this"/>
                 action="anotherPage?faces-redirect=true" 

...

Note, I have tried using immediate="true", however Apply Request Values phase still runs, which results in a NPE for me in a getter in my managed bean (as I no longer have the data that my getter needs).

Upvotes: 3

Views: 6391

Answers (2)

BalusC
BalusC

Reputation: 1109072

Just use <h:button> or <p:button>. It sends a normal GET request. There's really no need for a POST-Redirect-GET request if it's just page-to-page navigation.

<h:button value="Navigate to Another Page" outcome="anotherPage" />

For the PrimeFaces look'n'feel, just replace h: by p:. Note that this component doesn't require a <h:form>. The link equivalent is the <h:link> (for which there's no PrimeFaces equivalent, there's anyway nothing which needs to be restyled).

See also:

Upvotes: 7

Petr Mensik
Petr Mensik

Reputation: 27526

Set attribute immediate to true on commandButton, this will skip all validations, conversions or updates. Attributes causes JSF lifecycle to jump from Apply request values phase directly to Render Response phase.

Upvotes: 1

Related Questions