6

If I have a JSF page that I want to link to where I don't need to communicate anything to that page and don't need to perform any validation on the page I'm linking from, should I always use an h:link?

Do I lose anything by not using a h:commandLink (with immediate="true" or execute="@this")?

Is there any difference between h:link and h:commandLink in this scenario?

BestPractices
  • 12,738
  • 29
  • 96
  • 140
  • 1
    possible duplicate of [When should I use h:outputLink instead of h:commandLink?](http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink) – BalusC Jun 26 '12 at 11:59

1 Answers1

16

The h:link will fire a full GET request. Only JSF lifecycle phases 1 (restore view) and 6 (render response) will be invoked. No conversion, no validation, no action.

Thus immediate="true" and execute="@this" won't work (they are not available for h:link at all).

Use h:link for pure page to page navigation and h:commandLink (which fires a POST request) if input data needs to be processed on the server.

Addendum:

As per BalusC's comment lifecycle phases 2 to 5 are not skipped for a GET request if the target page contains f:viewParams.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112