Saturday, 6 June 2015

Auto dismiss popup component with Panel Window

This blog we will see how to close popup with panel window automatically after predefined time.

Lets create af:commandButton  and af:popup in  a page. On click of button we will display the popup but the popup will close automatically after 3 seconds (3000ms).

The below steps we will follow for auto dismiss the popup.
         1. Create af:poll event inside af:popup.
         2. Set the timeout for the af:poll event.
         3. Create a poll listener method inside bean where we will close the popup through the popup binding.
         4. Stop the poll calling multiple times.

The below will be the code stuffs:


<af:popup id="displayPopup" contentDelivery="lazyUncached" binding="#{backingBeanScope.backing_PopupClose.popUpBind}">
          <af:panelWindow id="pw14" modal="true" closeIconVisible="false"
                          contentWidth="318"
                          styleClass="AFStretchWidth">
            <af:panelStretchLayout id="psl19" inlineStyle=""
                                   styleClass="AFStretchWidth"
                                   topHeight="0px" bottomHeight="50px"
                                   dimensionsFrom="children">
              <f:facet name="center">
                <af:panelGroupLayout layout="vertical" halign="center">
                  <af:outputText value="Popup wil close after 3 sec."
                                 inlineStyle="line-height: 35px;"/>
                </af:panelGroupLayout>
              </f:facet>
            </af:panelStretchLayout>
          </af:panelWindow>
          <af:poll binding="#{backingBeanScope.backing_PopupClose.pollBind}"
                    pollListener="#{backingBeanScope.backing_PopupClose.pollListener}"
                           id="p1" timeout="3001"/>
        </af:popup>

Beans:


    public void pollListener(PollEvent pollEvent) {
        popUpBind.hide();// close the popup
        pollBind.setRendered(false); // stop poll event calling
    }

Note: For panel window and dialog we will follow the above steps for auto dismiss the popup. In case of note window we will set autoDismissalTimeout=”3”.

You can download the code: Download