Skip to main content

OTN Appreciation Day: Programmatically Dismiss Popup

A couple of years ago I blogged about fading user feedback.  Also Duncan Mills had a solution for this, as did Frank Nimphius.

Just recently I was triggered by a blogpost of Shay Schmeltzer that in ADF 12.2.1.1 this can be done completely different and 100% declarative. Where Shay's example is declarative, in this blogpost I describe how to do the same when this popup is created programmatically.

To explain this, first of all I need to show you how to invoke a popup programmatically. In order to do this we need to have a popup component defined on the page. To have access to the popup in java code, we need to bind the popup to a managed bean:

1:        <af:popup id="p1" animate="true"  binding="#{backingBeanScope.utilBean.dismissablePopup}" >  
2:        <af:panelGroupLayout id="pg1" layout="horizontal" halign="center" styleClass="AFStretchWidth">  
3:            <af:image source="#{resource['images:qual_approved_32_full.png']}" id="i1"/>  
4:            <af:outputFormatted value="I will dissappear in #{backingBeanScope.utilBean.seconds} seconds" id="of1"/>  
5:          </af:panelGroupLayout>  
6:        </af:popup>  

This managed bean (in backing bean scope) contains also the code to invoke the popup. This code is called by a couple of different buttons. Just for the sake of this example, I created 3 buttons that will show the popup for 1,2 or 3 seconds respectively. In a real life scenario, you would typically set the value based on, for instance, message severity, or maybe use some kind of user preference. Anyway, the buttons are on the page and call out to these methods in our managed bean.

1:              <af:gridRow marginTop="5px" height="auto" id="gr2">  
2:                <af:gridCell marginStart="5px" width="34%" id="gc4">  
3:                  <af:button text="Show Popup 1 second" id="b1"  
4:                        actionListener="#{backingBeanScope.utilBean.ShowPopupOneSeconds}"/>  
5:                </af:gridCell>  
6:                <af:gridCell marginStart="5px" width="33%" id="gc5">  
7:                  <af:button text="Show Popup 2 seconds" id="b2"  
8:                        actionListener="#{backingBeanScope.utilBean.ShowPopupTwoSeconds}"/>  
9:                </af:gridCell>  
10:                <af:gridCell marginStart="5px" width="33%" marginEnd="5px" id="gc6">  
11:                  <af:button text="Show Popup 3 seconds" id="b3"  
12:                        actionListener="#{backingBeanScope.utilBean.ShowPopupThreeSeconds}"/>  
13:                </af:gridCell>  
14:              </af:gridRow>  

In the managed bean, there are the 3 methods that are called by the buttons. In these beans, a member variable is used to set and hold the number of seconds that it takes before the popup disappears. It is very simple actually. There are 3 like the one below:

1:    public void ShowPopupOneSeconds(ActionEvent actionEvent) {  
2:      setSeconds(1);  
3:      ShowPopup();  
4:    }  

Finally, in the showPopup method, all is put together, so the popup will show, and after that, automatically disappear after the expected number of seconds:

1:    public void ShowPopup() {  
2:         RichPopup.PopupHints hints = new RichPopup.PopupHints();         
3:         this.getDismissablePopup().setAutoDismissalTimeout(this.seconds);        
4:         this.getDismissablePopup().show(hints);     
5:     }  

That is all. As of ADF 12.2.1.1 it is indeed very simple to make a popup disappear after some time.

Note: This blogpost is written as part of the OTN Appreciation Day Global Initiative. Thanks to all people at Oracle Technology Network, and the Oracle ACE Program for all the valuable work you do, and for helping the Oracle Community around the world to do their work.

Comments

Popular posts from this blog

ADF 11g popup and panelwindow: Open wikipedia in a modal popup.

This post was more or less inspired by the noteWindow example on Oracles tag demo site. When hovering the highlighted text in this example the user gets extra information about the subject. I wanted to give the end user the opportunity to get even more information, for instance by invoking a wikipedia page about the subject. The catch here is that I wanted this information to be shown in a modal popup, and one that is not prohibited by popup blockers. Luckily ADF 11g provides javascript popups that can also be made modal, so the user has to close the popup before returning to the application. This post describes how I used an in a to open the correct wikipedia in a modal popup. Step 1: Create the plain text that invokes the noteWindow. This is taken directly from the mentioned Oracle example. <p style="margin-left:30px;width:500px;margin-right:30px;line-height:16px"> Vultures are scavenging birds, feeding mostly on the carcasses of dead animals...

ADF 11g : Show PDF in a Popup

In one of my previous posts I showed how to use ADF popup components to display external content such as webpages like wikipedia in an inline frame. Based on this post a colleague of mine tried to display a PDF document. That didn't work. In this post I explain how you can use a servlet to open a PDF document in the inline frame. I will not explain how to invoke popups. If you need to know how to do that, refer to the post mentioned earlier. How to create the servlet ? The solution for showing a PDF in a popup is to use a servlet. It's possible to have a servlet deliver PDF content to the browser by specifying the content type of the servlet response to be the 'application/pdf' MIME type via 'response.setContentType("application/pdf")'. In JDeveloper you can create a HTTP servlet very easy via the new gallery. I decided to call the servlet ShowPdfServlet which actually is a pretty descriptive name for this servlet. For the servlet mapping I accept th...

ADF 11g : Printing Directly From Your Application

Last week I was asked this question : "Can we print directly from within our ADF Application, without invoking the printer dialog ?" I wasn't sure but after some investigation the answer was clear. Yes you can ! Here is how... I decided to create a print start up form where I can select printers and print the document. Most of the functionality needed is provided by the Java Print Service API. Selecting available printers I start with a way to show all printers available to the session. For that I simply use the PrinterServiceLookup. PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null); The result I can now use to create an Array of SelectItems in order to make the list available in the application. 1: public SelectItem[] getAllPrinters() { 2: if (allPrinters == null) { 3: PrintService[] printers = 4: PrintServiceLookup.lookupPrintServices(null, null); 5: allPrinters = new SelectItem[printers.length]; 6: for (int i = 0; i ...