Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

h:commandbutton vs h:commandlink

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?

like image 649
user684434 Avatar asked May 21 '12 16:05

user684434


2 Answers

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?

like image 171
BalusC Avatar answered Sep 20 '22 03:09

BalusC


For a form, I prefer the h:commandbutton

h:commandbutton is like a button in HTML where you can set the action of a backing bean. h:commandlink is like a link in HTML (the tag a) where you also can set the action of a backing bean

To use the css style in JSF, you can use the attribute 'styleClass'.

like image 33
Felipe Queiroz Avatar answered Sep 21 '22 03:09

Felipe Queiroz