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

How to: Adding Speech to Oracle Digital Assistant; Talk to me Goose

At Oracle Code One in October, and also on DOAG in Nurnberg Germany in November I presented on how to go beyond your regular chatbot. This presentation contained a part on exposing your Oracle Digital Assistant over Alexa and also a part on face recognition. I finally found the time to blog about it. In this blogpost I will share details of the Alexa implementation in this solution. Typically there are 3 area's of interest which I will explain. Webhook Code to enable communication between Alexa and Oracle Digital Assistant Alexa Digital Assistant (DA) Explaining the Webhook Code The overall setup contains of Alexa, a NodeJS webhook and an Oracle Digital Assistant. The webhook code will be responsible for receiving and transforming the JSON payload from the Alexa request. The transformed will be sent to a webhook configured on Oracle DA. The DA will send its response back to the webhook, which will transform into a format that can be used by an Alexa device. To code

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