PrimeFaces block UI does not work when the component to be blocked is updated via AJAX

邮差的信 提交于 2019-12-10 21:01:05

问题


I have displayed some components in <p:panel> as follows.

<p:growl id="growl" />

<p:panel id="panel" header="New User" style="margin-bottom:10px;">
    <p:messages id="messages" />
    <h:panelGrid columns="3">
        <h:outputLabel for="firstName" value="FirstName: *" />
        <p:inputText id="firstName" required="true" label="FirstName">
            <f:validateLength minimum="2" />
        </p:inputText>
        <p:message for="firstName" />

        <h:outputLabel for="surname" value="Surname: *" />
        <p:inputText id="surname" required="true" label="Surname"/>
        <p:message for="surname" />
    </h:panelGrid>

    <p:commandButton id="saveBtn" value="Save" icon="ui-icon-check" 
                     style="margin:0" 
                     actionListener="#{testManagedBean.insert}" 
                     update="growl panel"/>
</p:panel>

<p:blockUI block="panel" trigger="saveBtn" />

When the given button is pressed, <p:growl> and <p:panel> need to be updated which is done through the update="growl panel" attribute of <p:commandButton>. <p:panel> doesn't block, in this case.

<p:panel> is blocked only when update="growl panel" is changed to update="growl" i.e when the panel is skipped from being updated.

Is there a way to make <p:blockUI> work? <p:panel> should be updated on pressing the command button.


回答1:


I have alternatively chosen the PrimeFaces Extensions' <pe:blockUI> that works well even after the component to block is updated by AJAX as follows.

<!--xmlns:pe="http://primefaces.org/ui/extensions"-->

<h:outputStylesheet library="default" name="css/block-ui.css"/>

<pe:blockUI target="panel" 
            content="blockPanelContents" 
            widgetVar="blockUIWidget"/>

<h:panelGrid id="blockPanelContents" columns="2" class="block-contents">
    <h:graphicImage library="default" 
                    name="images/ajax-loader1.gif" 
                    class="block-ui-image"/>

    <h:outputText value="Sending data..." class="block-ui-text"/>
</h:panelGrid>

<p:commandButton id="saveBtn" update="growl panel" 
                 onstart="PF('blockUIWidget').block();" 
                 oncomplete="PF('blockUIWidget').unblock();" 
                 actionListener="#{testManagedBean.insert}" 
                 icon="ui-icon-check" value="Save"/>

The CSS classes used as indicated by <h:outputStylesheet>:

.block-ui-image {
    margin-right: 12px; vertical-align: middle;
}

.block-ui-text {
    white-space: nowrap;
}

.block-contents {
    border: none !important;
    padding: 0 !important;
    display:none;
}


来源:https://stackoverflow.com/questions/20028923/primefaces-block-ui-does-not-work-when-the-component-to-be-blocked-is-updated-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!