Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should one use h:link instead of h:commandLink?

Tags:

jsf-2

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?

like image 328
BestPractices Avatar asked Jun 26 '12 11:06

BestPractices


People also ask

What is H command link in HTML?

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.

How do I create a command link event in HTML?

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.

What is the value of the attribute “link”?

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.

What is the relationship between a document and a link?

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.


1 Answers

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.

like image 79
Matt Handy Avatar answered Nov 09 '22 06:11

Matt Handy