Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:34:26+00:00 2026-05-18T08:34:26+00:00

When should I use an <h:outputLink> instead of an <h:commandLink> ? I understand that

  • 0

When should I use an <h:outputLink> instead of an <h:commandLink>?

I understand that a commandLink generates an HTTP post; I’m guessing that outputLink will generate HTTP gets. That said, most of the JSF tutorial material I’ve read uses commandLink (almost?) exclusively.

Context: I am implementing a wee little demo project that shows a header link to a user page, much like Stack Overflow’s…

needs more jquery

…and I am not sure if commandLink (perhaps using ?faces-redirect=true for bookmarkability) or outputLink is the right choice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:34:26+00:00Added an answer on May 18, 2026 at 8:34 am

    The <h:outputLink> renders a fullworthy HTML <a> element with the proper URL in the href attribute which fires a bookmarkable GET request. It cannot directly invoke a managed bean action method.

    <h:outputLink value="destination.xhtml">link text</h:outputLink>
    

    The <h:commandLink> renders a HTML <a> 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 <h:form>.

    <h:form>
        <h:commandLink value="link text" action="destination" />
    </h:form>
    

    The ?faces-redirect=true parameter on the <h:commandLink>, 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 <a> element to be a fullworthy URL. It still remains #.

    <h:form>
        <h:commandLink value="link text" action="destination?faces-redirect=true" />
    </h:form>
    

    Since JSF 2.0, there’s also the <h:link> which can take a view ID (a navigation case outcome) instead of an URL. It will generate a HTML <a> element as well with the proper URL in href.

    <h:link value="link text" outcome="destination" />
    

    So, if it’s for pure and bookmarkable page-to-page navigation like the SO username link, then use <h:outputLink> or <h:link>. 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 <f:viewParam> to set GET parameters as bean properties.

    See also:

    • ViewParam vs @ManagedProperty(value = "#{param.id}")
    • What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
    • Bookmarkability via View Parameters feature
    • How to navigate in JSF? How to make URL reflect current page (and not previous one)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know you should use POST whenever data will be modified on a public
What framework I should use to grab XML from a http and parse that?
Why sometimes I should use block and other times &block inside functions that accept
I wonder why I should use: puts In folder #{File.join ENV[HOME], projects} Instead of:
I heard that static methods should use only static variables in java. But, main
I have a bunch of methods that make use of jquery to basically generate
One CSS rule I have learned is that you should use the relative em
I realize that we should use BigDecimal for all monetary values, but what about
MSDN says that you should use structs when you need lightweight objects. Are there
I've read I should use money , but in todays fast paced world maybe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.