Search code examples
jsfjsf-2primefacesblockui

Primefaces <p:blockUI> hidding growl <p:growl> after releasing


I'm trying to update message by clicking button from backing bean and in the same time after clicking button I'm trying to block this button to avoid doubleclick. Blocking occurs successfully and message appears, but after the unblocking message disappears. This happens pretty quickly. And I want the message in growl stay longer. My .jsf snippet.

<h:form id="form">
    <p:growl id="messages" />
    <p:blockUI block="button" widgetVar="block"/>
        <p:dataTable var="item" id="table" value="#{bean.lazyModel}"
            lazy="true">
            <p:column>
                <p:commandButton value="#{item.actionBtn}" 
                    update=":form:messages" action="#{bean.action}"
                    oncomplete="filterTableFromPanel();PF('block').hide()"
                    onclick="PF('block').show()">
                </p:commandButton>
            </p:column>
        </p:dataTable> 
</h:form>

In backing bean all just as usual.

public void action(){
   FacesContext.getCurrentInstance().addMessage(null, msg);
}

Please, forgive me for possible mistakes, snipet is trimmed.


Solution

  • I've resolved my problem using p:remoteCommand.

    <h:form id="form">
        <p:growl id="messages" />
        <p:blockUI block="button" widgetVar="block"/>
        <p:remoteCommand name="addMessage"
    			action="#{bean.addMessage}"
    			update=":form:messages" />
            <p:dataTable var="item" id="table" value="#{bean.lazyModel}"
                lazy="true">
                <p:column>
                    <p:commandButton value="#{item.actionBtn}" 
                        update=":form:messages" action="#{bean.action}"
                        oncomplete="filterTableFromPanel();PF('block').hide(); addMessage()"
                        onclick="PF('block').show()">
                    </p:commandButton>
                </p:column>
            </p:dataTable> 
    </h:form>

    In backing bean I've add somethhing like this:

    public void addMessage(){
       FacesContext.getCurrentInstance().addMessage(null, "msg");
    }