Tuesday, April 25, 2017

ADF: Popup gets closed automatically

Problem description: I found at times people complaint that ADF popup gets closed automatically.
In this blog I am trying to figure out possible cause of popup getting closed.

Possible cause: There are following four scenarios when a popup gets closed.
          1. User selects default buttons or close icon of dialog
          2. User programmatically closes popup using hide function
          3. User hit enter/escape key
          4. Popup or its parent component gets refreshed.

In first two points popup getting closed is desired behavior.

In third case when you use default buttons of popup, it gets closed with enter/escape keys. If you don't want you can use custom buttons as suggested in blog https://blogs.oracle.com/jheadstart/entry/adf_faces_how_to_prevent_closi

Point 4 is most problamatic, when user is not doing anything to close popup but it gets closed automatically. This happens when as a ppr we refresh popup or any of its parent component.
Lets take a scenario:
You have an inputText on popup the moment you enter its value and tab out your popup is getting closed. This may be because you are refreshing popup or any of its parent component. When you do so popup gets closed automatically. Your popup or any parent component of it might have partialtrigger property pointing to inputText. Or you may have valuechangeListener on inputText and you programmatically using addPartialTarget trying to refresh a component, which is having popup as child component in hierarchy.

Most of the time this happens accidentally. You decide to refresh UI component on base page and forget that same UI component is having popup also as child component. As a good practice I can suggest that we should move all our popups in single panelGroupLayout and keep them somewhere close to root components. For example

PanelGroupLayout -container
    PanelGroupLayout - main  [Keep your main page content here]
    PanelGroupLayout - popus  [Keep all your popups together here]
        af:popup1
        af:popup2

Keeping popups out of main page ensure that you can freely refresh main page components while working on popups.
One exception to this rule I see is when you have inline popups. For example you have a table and every row is showing some information in popup (may be on hover) and you have added popup inside a column with contentDelivery=immediate to make sure that popup launches quick with making a server trip. In such cases you have to add popup inside and refer #{row.myAttribute} kind of expression's EL in those.


Thats all.