• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

BlockUI

BlockUI blocks any piece(s) of a page, or the entire page, during Ajax calls. A "source" component blocks one or more "target" components with an overlay and custom content.

BlockUI Tag Documentation

BlockUI blocks user interaction with the page or a specific component while content is loading.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
widgetVar String false generated ('widget_' + componentClientId) Name of the client side widget.
autoShow boolean false false When true, the block is shown automatically when source triggers.
centerX boolean false true Whether to center the block message horizontally.
centerY boolean false true Whether to center the block message vertically.
content String false Search expression for the component whose markup is used as blocking content.
css String false CSS to be applied to the blocking overlay.
cssOverlay String false CSS to be applied to the overlay element.
event String false Comma-separated list of event names that trigger the block. If empty, all events from source are accepted.
fadeIn Integer false 200 Fade-in duration in milliseconds.
fadeOut Integer false 400 Fade-out duration in milliseconds.
focusInput boolean false true Whether to focus the first input in the block content.
showOverlay boolean false true Whether to show the overlay.
source String false parent Search expression for the component(s) to block.
target String false Search expression for the element to use as the blocking container.
timeout Integer false 0 Timeout in milliseconds to automatically unblock. 0 means no timeout.
Tag Documentation Widget Source
Basic usage with p:ajax

Uses the widget's block() / unblock() as onstart / oncomplete callbacks. Add a message, or page and sort the table.

Subject *
Text *
SubjectText
subject 0text 0
subject 1text 1
subject 2text 2
subject 3text 3
subject 4text 4
AutoShow mode and more

With autoShow="true" the source component's Ajax events (see event) block the target component(s) automatically. Only events defined by p:ajax are supported. Expand, select or unselect a tree node, or click a checkbox.

No tree node is selected
Page Blocking

The entire page is blocked when the target attribute is omitted. The button blocks the whole page for the duration of the Ajax call.

Non-centered message, auto-unblock and more

A non-centered message defined by css and centerX / centerY, a styled overlay via cssOverlay, and auto-unblocking after timeout milliseconds. The whole page is blocked for two seconds.

Usage modes

There are two ways to use BlockUI. The first uses the widget's JavaScript API (block() / unblock()) in onstart / oncomplete callbacks. The second, so-called autoShow mode, hooks into jQuery global Ajax callbacks so no explicit calls are needed. Components and p:ajax with global="false" do not trigger BlockUI in autoShow mode.

Some HTML elements such as table or span cannot be blocked; wrap them in a div (h:panelGroup layout="block"). Multiple blockings of the same element by different Ajax calls are tracked: the element is unblocked only after all calls have finished.

Usage


<style>
    #formBlockUIAjax\:blockUIContent td {
        border: none !important;
        padding: 0 !important;
    }
</style>

<div class="card">
    <h5>Basic usage with p:ajax</h5>
    <p>Uses the widget's <code>block()</code> / <code>unblock()</code> as <code>onstart</code> / <code>oncomplete</code> callbacks. Add a message, or page and sort the table.</p>
    <h:form id="formBlockUIAjax">
        <p:messages id="messages"/>
        <div class="grid">
            <div class="col-12 md:col-4">
                <h:panelGroup id="messageDetailGroup" layout="block">
                    <h:panelGrid id="messageDetail" columns="1">
                        <h:outputText value="Subject *"/>
                        <h:inputText value="#{dataTableController.newSubject}" required="true" label="Subject"/>
                        <h:outputText value="Text *"/>
                        <h:inputText value="#{dataTableController.newText}" required="true" label="Text"/>
                    </h:panelGrid>
                    <p:commandButton id="addMsgButton" value="Add message" action="#{dataTableController.addMessage}"
                                     process="messageDetailGroup" update="messageDetail dataTable messages"
                                     style="margin-top: 20px;" icon="pi pi-plus"
                                     onstart="PF('blockUIWidget1').block()" oncomplete="PF('blockUIWidget1').unblock()"/>
                </h:panelGroup>
            </div>
            <div class="col-12 md:col-8">
                <p:dataTable id="dataTable" var="message" value="#{dataTableController.messages}" paginator="true"
                             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rows="5" rowsPerPageTemplate="5,10,15" paginatorPosition="bottom">
                    <p:ajax event="page" listener="#{dataTableController.doSomething}" update="messages"
                            onstart="PF('blockUIWidget2').block()" oncomplete="PF('blockUIWidget2').unblock()"/>
                    <p:ajax event="sort" listener="#{dataTableController.doSomething}" update="messages"
                            onstart="PF('blockUIWidget2').block()" oncomplete="PF('blockUIWidget2').unblock()"/>
                    <p:column sortBy="#{message.subject}" headerText="Subject">
                        <h:outputText value="#{message.subject}"/>
                    </p:column>
                    <p:column sortBy="#{message.text}" headerText="Text">
                        <h:outputText value="#{message.text}"/>
                    </p:column>
                </p:dataTable>
            </div>
        </div>
        <pe:blockUI target="messageDetailGroup" widgetVar="blockUIWidget1">
            <h:panelGrid columns="2">
                <h:graphicImage library="images" name="ajax-loader1.gif"
                                style="margin-right: 12px; vertical-align: middle;"/>
                <h:outputText value="Adding message..." style="white-space: nowrap;"/>
            </h:panelGrid>
        </pe:blockUI>
        <pe:blockUI target="dataTable" content="blockUIContent" widgetVar="blockUIWidget2"/>
        <h:panelGrid id="blockUIContent" columns="2" style="display:none;table-layout:auto;">
            <h:graphicImage library="images" name="ajax-loader1.gif"
                            style="margin-right: 12px; vertical-align: middle;"/>
            <h:outputText value="Please wait, data is being processed..." style="white-space: nowrap;"/>
        </h:panelGrid>
    </h:form>
</div>

<div class="card">
    <h5>AutoShow mode and more</h5>
    <p>With <code>autoShow="true"</code> the <code>source</code> component's Ajax events (see <code>event</code>) block the <code>target</code> component(s) automatically.
        Only events defined by <code>p:ajax</code> are supported. Expand, select or unselect a tree node, or click a checkbox.</p>
    <h:form id="formBlockUIAutoShow">
        <h:panelGroup id="viewArea" layout="block">
            <div class="grid">
                <div class="col-12 md:col-6">
                    <h:panelGroup layout="block" styleClass="blockable">
                        <p:tree id="fileSystem" value="#{fileSystemController.root}" var="node" dynamic="true"
                                cache="false" selectionMode="single" selection="#{fileSystemController.selectedNode}">
                            <p:ajax event="expand" update="accessRightsGroup"
                                    listener="#{fileSystemController.onNodeExpand}"/>
                            <p:ajax event="select" update="accessRightsGroup"
                                    listener="#{fileSystemController.onNodeSelect}"/>
                            <p:ajax event="unselect" update="accessRightsGroup"
                                    listener="#{fileSystemController.onNodeUnselect}"/>
                            <p:treeNode>
                                <h:outputText value="#{node}"/>
                            </p:treeNode>
                        </p:tree>
                    </h:panelGroup>
                </div>
                <div class="col-12 md:col-6">
                    <h:panelGroup layout="block" id="accessRightsGroup" styleClass="blockable">
                        <h:outputText value="Access rights for #{fileSystemController.selectedNode.data}"
                                      rendered="#{not empty fileSystemController.selectedNode}"/>
                        <h:outputText value="No tree node is selected" rendered="#{empty fileSystemController.selectedNode}"/>
                        <h:selectManyCheckbox id="accessRights" value="#{accessRightsController.selectedAccessRights}"
                                              styleClass="checkBoxes" layout="pageDirection" style="margin-top: 10px;">
                            <f:selectItems value="#{accessRightsController.accessRights}"/>
                            <p:ajax process="@this"/>
                        </h:selectManyCheckbox>
                        <pe:blockUI source="accessRights" target="@(.blockable)" autoShow="true">
                            <h:panelGrid columns="2">
                                <h:graphicImage library="images" name="ajax-loader1.gif"
                                                style="margin-right: 12px; vertical-align: middle;"/>
                                <h:outputText value="Checkbox clicked..." style="white-space: nowrap;"/>
                            </h:panelGrid>
                        </pe:blockUI>
                    </h:panelGroup>
                </div>
            </div>
        </h:panelGroup>
        <pe:blockUI source="fileSystem" target="viewArea" event="expand,select,unselect" autoShow="true">
            <h:panelGrid columns="2">
                <h:graphicImage library="images" name="ajax-loader1.gif"
                                style="margin-right: 12px; vertical-align: middle;"/>
                <h:outputText value="Tree event is running..." style="white-space: nowrap;"/>
            </h:panelGrid>
        </pe:blockUI>
    </h:form>
</div>

<div class="card">
    <h5>Page Blocking</h5>
    <p>The entire page is blocked when the <code>target</code> attribute is omitted. The button blocks the whole page for the duration of the Ajax call.</p>
    <h:form id="formBlockPage">
        <p:commandButton value="Block this page!" action="#{blockUIController.doSomething}" update="@none"
                         onstart="PF('blockUIWidgetPage').block()" oncomplete="PF('blockUIWidgetPage').unblock()"/>
        <pe:blockUI widgetVar="blockUIWidgetPage" cssOverlay="{opacity:0.5}">
            <h:panelGrid columns="2">
                <h:graphicImage library="images" name="ajax-loader1.gif"
                                style="margin-right: 12px; vertical-align: middle;"/>
                <h:outputText value="Please wait..." style="white-space: nowrap;"/>
            </h:panelGrid>
        </pe:blockUI>
    </h:form>
</div>

<div class="card">
    <h5>Non-centered message, auto-unblock and more</h5>
    <p>A non-centered message defined by <code>css</code> and <code>centerX</code> / <code>centerY</code>, a styled overlay via <code>cssOverlay</code>,
        and auto-unblocking after <code>timeout</code> milliseconds. The whole page is blocked for two seconds.</p>
    <h:form id="formBlockCustom">
        <p:commandButton value="Block this page!" type="button"
                         onclick="PF('blockUIWidgetCustom').block()"/>
        <pe:blockUI widgetVar="blockUIWidgetCustom"
                    css="{top: '10px', left: '', right: '10px', cursor: 'wait'}"
                    cssOverlay="{backgroundColor: 'red'}"
                    timeout="2000"
                    centerY="false">
            <h:panelGrid columns="2">
                <h:graphicImage library="images" name="ajax-loader1.gif"
                                style="margin-right: 12px; vertical-align: middle;"/>
                <h:outputText value="This is a non-centered message. Please wait..." style="white-space: nowrap;"/>
            </h:panelGrid>
        </pe:blockUI>
    </h:form>
</div>