We are using JSF-2.1.7 and in all our form post requests. I am trying to justify whether to use <h:commandButton> or <h:commandLink> . The appearance of <h:commandLink> (href <a/> ) can be controlled using style and jQuery.
Which is recommended <h:commandButton> or <h:commandLink>? Is there any real advantage?
There is no functional difference apart from the generated markup and the appearance. The
<h:commandButton>generates a HTML<input type="submit">element and the<h:commandLink>generates a HTML<a>element which uses JavaScript to submit the form. Both are to be used to submit a form. Additional styling is irrelevant to the functionality.Use the
<h:commandButton>if you need a submit button and use the<h:commandLink>if you need a submit link. If that doesn't make sense to you, then I don't know. If you can't decide which one to use, just choose the one which makes the most sense in UI perspective. Ask the web designer if you're unsure.The difference between
<h:commandLink>and<h:outputLink>is by the way more interesting. This is been answered in detail here: When should I use h:outputLink instead of h:commandLink?