Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/outputLink.html" rel="noreferrer"><code>&lt;h:outputLink&gt;</code></a> renders a fullworthy HTML <code>&lt;a&gt;</code> element with the proper URL in the <code>href</code> attribute which fires a bookmarkable GET request. It cannot directly invoke a managed bean action method. </p> <pre class="lang-xml prettyprint-override"><code>&lt;h:outputLink value="destination.xhtml"&gt;link text&lt;/h:outputLink&gt; </code></pre> <hr> <p>The <a href="http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/commandLink.html" rel="noreferrer"><code>&lt;h:commandLink&gt;</code></a> renders a HTML <code>&lt;a&gt;</code> element with an <code>onclick</code> script which submits a (hidden) POST form and can invoke a managed bean action method. It's also required to be placed inside a <code>&lt;h:form&gt;</code>.</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:form&gt; &lt;h:commandLink value="link text" action="destination" /&gt; &lt;/h:form&gt; </code></pre> <p>The <code>?faces-redirect=true</code> parameter on the <code>&lt;h:commandLink&gt;</code>, which triggers a redirect after the POST (as per the <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get" rel="noreferrer">Post-Redirect-Get</a> pattern), only improves bookmarkability of the target page when the link is actually clicked (the URL won't be "one behind" anymore), but it doesn't change the <code>href</code> of the <code>&lt;a&gt;</code> element to be a fullworthy URL. It still remains <code>#</code>.</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:form&gt; &lt;h:commandLink value="link text" action="destination?faces-redirect=true" /&gt; &lt;/h:form&gt; </code></pre> <hr> <p>Since JSF 2.0, there's also the <a href="http://download.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/h/link.html" rel="noreferrer"><code>&lt;h:link&gt;</code></a> which can take a view ID (a navigation case outcome) instead of an URL. It will generate a HTML <code>&lt;a&gt;</code> element as well with the proper URL in <code>href</code>.</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:link value="link text" outcome="destination" /&gt; </code></pre> <hr> <p>So, if it's for pure and bookmarkable page-to-page navigation like the SO username link, then use <code>&lt;h:outputLink&gt;</code> or <code>&lt;h:link&gt;</code>. That's also better for SEO since bots usually doesn't cipher POST forms nor JS code. Also, UX will be improved as the pages are now bookmarkable and the URL is not "one behind" anymore.</p> <p>When necessary, you can do the preprocessing job in the constructor or <code>@PostConstruct</code> of a <code>@RequestScoped</code> or <code>@ViewScoped</code> <code>@ManagedBean</code> which is attached to the destination page in question. You can make use of <code>@ManagedProperty</code> or <code>&lt;f:viewParam&gt;</code> to set GET parameters as bean properties. </p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/4888942">ViewParam vs @ManagedProperty(value = &quot;#{param.id}&quot;)</a></li> <li><a href="https://stackoverflow.com/questions/6377798">What can &lt;f:metadata&gt;, &lt;f:viewParam&gt; and &lt;f:viewAction&gt; be used for?</a></li> <li><a href="https://stackoverflow.com/questions/13249844">Bookmarkability via View Parameters feature</a></li> <li><a href="https://stackoverflow.com/questions/15521451">How to navigate in JSF? How to make URL reflect current page (and not previous one)</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload