Difference between h:button and h:commandButton

前端 未结 5 1700
轮回少年
轮回少年 2020-11-22 06:26

In JSF 2, what is the difference between h:button and h:commandButton ?

5条回答
  •  眼角桃花
    2020-11-22 06:56

    This is taken from the book - The Complete Reference by Ed Burns & Chris Schalk

    h:commandButton vs h:button

    What’s the difference between h:commandButton|h:commandLink and h:button|h:link ?

    The latter two components were introduced in 2.0 to enable bookmarkable JSF pages, when used in concert with the View Parameters feature.

    There are 3 main differences between h:button|h:link and h:commandButton|h:commandLink.

    First, h:button|h:link causes the browser to issue an HTTP GET request, while h:commandButton|h:commandLink does a form POST. This means that any components in the page that have values entered by the user, such as text fields, checkboxes, etc., will not automatically be submitted to the server when using h:button|h:link. To cause values to be submitted with h:button|h:link, extra action has to be taken, using the “View Parameters” feature.

    The second main difference between the two kinds of components is that h:button|h:link has an outcome attribute to describe where to go next while h:commandButton|h:commandLink uses an action attribute for this purpose. This is because the former does not result in an ActionEvent in the event system, while the latter does.

    Finally, and most important to the complete understanding of this feature, the h:button|h:link components cause the navigation system to be asked to derive the outcome during the rendering of the page, and the answer to this question is encoded in the markup of the page. In contrast, the h:commandButton|h:commandLink components cause the navigation system to be asked to derive the outcome on the POSTBACK from the page. This is a difference in timing. Rendering always happens before POSTBACK.

提交回复
热议问题