When should I use an
instead of an
?
I understand that a commandLink
generates an HT
The element with the proper URL in the
href
attribute which fires a bookmarkable GET request. It cannot directly invoke a managed bean action method.
link text
The element with an
onclick
script which submits a (hidden) POST form and can invoke a managed bean action method. It's also required to be placed inside a
.
The ?faces-redirect=true
parameter on the
, which triggers a redirect after the POST (as per the Post-Redirect-Get 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 href
of the element to be a fullworthy URL. It still remains
#
.
Since JSF 2.0, there's also the element as well with the proper URL in
href
.
So, if it's for pure and bookmarkable page-to-page navigation like the SO username link, then use
or
. 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.
When necessary, you can do the preprocessing job in the constructor or @PostConstruct
of a @RequestScoped
or @ViewScoped
@ManagedBean
which is attached to the destination page in question. You can make use of @ManagedProperty
or
to set GET parameters as bean properties.