p:commandButton vs. h:commandButton

前端 未结 1 1343
轻奢々
轻奢々 2020-11-29 12:27

When I am using a PrimeFaces p:commandButton


I don\'t see the the validation m

相关标签:
1条回答
  • 2020-11-29 13:22

    Like @Partlov wrote in the comments below the question,

    Main difference is that p:commandButton is AJAX by default, and h:commandButton is non-AJAX by default.

    So

    <p:commandButton ... />
    

    is more like

    <h:commandButton ...>
        <f:ajax/>
    </h:commandButton>
    

    but

    <p:commandButton ...>
        <p:ajax/>
    </p:commandButton>
    

    is wrong and leads to undefined behaviour

    or the other way around

    <h:commandButton ... />
    

    is like

    <p:commandButton ajax="false" ... />
    

    The p:commandButton will submit the form by default. However by default it does not update anything in the form after the ajax call is finished so the messages are not displayed (which in development mode would have shown in the log files that messages were enqueued but not displayed) . The non-ajax h:commandButton does a full page refresh that does show the messages. In order to get the form (which contains the message component) updated when using the p:commandButton you need to add the update attribute:

    <p:commandButton action="#{reliefHourHeadManagedBean.copyReliefHourHead}" value="Kopieren" icon="ui-icon-copy" update="@form">
        <f:param name="reliefhourhead_id" value="#{reliefHourHeadManagedBean.reliefHourHeadId}" />
    </p:commandButton>
    

    Adding an (superfluous) f:ajax or p:ajax inside a p:commandXXX can result in strange undefined behaviour

    See also

    • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
    0 讨论(0)
提交回复
热议问题