Search code examples
jsfprimefacesblockui

How to disable p:defaultCommand when blockUI is active?


I am using Primefaces 7.0 and want to disable the defaultCommand when the blockUI is active... My Problem is, when i hit the SaveButton the blockUI is active, but i can still press ENTER and the defaultCommand gets triggered. How can i disable this? I dont want to disable the defaultCommand always.

<h:form id="form">  

    <p:panel id="pnlContent">
        <p:commandButton value="SaveButton" id="btnSave" action="#{defaultView.longRunningOperation}"/>

        <p:defaultCommand target="btnSave"/>
    </p:panel>

    <p:blockUI block="pnlContent" trigger="btnSave"/>

</h:form>

Solution

  • You can drop the focus from all components within the blocked panel by invoking JQuery.blur() on them:

    <p:commandButton value="SaveButton" id="btnSave"
        onclick="$(PrimeFaces.escapeClientId('form:pnlContent') + ' *').blur()" />
    

    This will prevent additional command invocations on subsequent pressing of enter.