3

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).

BestPractices
  • 12,738
  • 29
  • 96
  • 140
  • I've hit a similar problem. In my case, I'm trying to invoke an action from a button that does not need any context on the rendered page. However, any `commandButton`, including ``, ajax or not, is causing the `` that was also rendered to take action during the Update Model Values phase (for no good reason that I can find). Since the backing data is gone (I don't need it past rendering), I get a NullPointerException. This does not happen with ``, only the Primefaces dataTable. – Brian May 11 '12 at 17:40
  • If you haven't already, you may want to create a new Stack Overflow question as your question is more specific this this one (i.e. problem with p:dataTable). You can always reference back to this question... – BestPractices May 11 '12 at 21:49

2 Answers2

7

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

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.

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • This unfortunately does not work for me -- 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 data that my getter needs). – BestPractices Mar 28 '12 at 19:55