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 12.1.3 : Implementing Default Table Filter Values

In one of my projects I ran into a requirement where the end user needs to be presented with default values in the table filters. This sounds like it is a common requirement, which is easy to implement. However it proved to be not so common, as it is not in the documentation nor are there any Blogpost to be found that talk about this feature. In this blogpost I describe how to implement this. The Use Case Explained Users of the application would typically enter today's date in a table filter in order to get all data that is valid for today. They do this each and every time. In order to facilitate them I want to have the table filter pre-filled with today's date (at the moment of writing July 31st 2015). So whenever the page is displayed, it should display 'today' in the table filter and execute the query accordingly. The problem is to get the value in the filter without the user typing it. Lets first take a look at how the ADF Search and Filters are implemented by...

ADF 11g Quicky 3 : Adding Error, Info and Warning messages

How can we add a message programatically ? Last week I got this question for the second time in a months time. I decided to write a short blogpost on how this works. Adding messages is very easy, you just need to know how it works. You can add a message to your faces context by creating a new FacesMessage. Set the severity (ERROR, WARNING, INFO or FATAL ), set the message text, and if nessecary a message detail. The fragment below shows the code for an ERROR message. 1: public void setMessagesErr(ActionEvent actionEvent) { 2: String msg = "This is a message"; 3: AdfFacesContext adfFacesContext = null; 4: adfFacesContext = AdfFacesContext.getCurrentInstance(); 5: FacesContext ctx = FacesContext.getCurrentInstance(); 6: FacesMessage fm = 7: new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, ""); 8: ctx.addMessage(null, fm); 9: } I created a simple page with a couple of buttons to show the result of setting the message. When the but...

ADF 12c : Using Jasper Reports en JasperSoft Studio 6.1; What Libraries do you need?

Over the last couple of years, or better in the last decade I have implemented several reporting solutions with Jasper Reports in ADF. I did that in ADF 10g, ADF 11.1.1.x, ADF 11.1.2.x and ADF 12.1.x I also used several version of Jasper Reports. There is a whole lot of documentation, blogposts and presentations available. So when today I got a request from one of my customers to make a setup for the implementation of Jasper Reports 6.1 in ADF 12.1.3 I did not expect any problems. Boy was I wrong. Here is the Story With all the knowledge from the past, I decided to follow the known steps. 1) Download iReport Designer, 2) Build a report in iReport 3) Create an ADF application 4) Add the necessary libraries to use the report 5) Call the report from a button via a Managed Bean Step 1 In the past I used iReport designer to build the reports. When you go to the download site of iReport designer you now see an interesting message. So I took this serious and decided not to u...