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?
The h:commandLink tag renders an HTML "anchor" element. A boolean; if true, requires a value to be entered in the associated field A key, typically combined with a system-defined metakey, that gives focus to an element Comma- or space-separated list of character encodings for a form.
An h:commandLink tag must include a nested h:outputText tag, which represents the text that the user clicks to generate the event. It's also required to be placed inside a <h:form> tag.
The value of the attribute is a space-separated list of link types A title, used for accessibility, that describes an element. Visual browsers typically create tooltips for the title’s value Let us create a test JSF application to test the above tag.
Relationship between the current document and a link specified with the href attribute Reverse link from the anchor specified with href to the current document. The value of the attribute is a space-separated list of link types A title, used for accessibility, that describes an element.
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:viewParam
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With