Logout with confirmation dialog

A question on OTN (http://forums.oracle.com/forums/forum.jspa?forumID=83) leads to this short article.

The use case requires to ask for a confirmation before logging out of the application.  This can easily implemented using a OK/Cancel dialog  which we show on a button click.

My simple test page looks like this:

On a click on the logout button we show a confirmation dialog as popup:

The dialog uses a dialog listener to catch the user input.  For an OK/Cancel dialog only the click on the OK button is passed to the listener. Closing the dialog or clicking cancel never calls the dialog listener. Clicking on OK navigates to a logout page:

Looks pretty simple,  still we need  a few things to mention. The code for the logout button and popup  looks like:

<af:panelGroupLayout id="pgl1">
  <af:commandButton text="Logout" id="cb2">
    <af:showPopupBehavior popupId="p1" triggerType="action"/>
  <af:popup id="p1">
    <af:dialog id="d2" dialogListener="#{LoginLogout.dialogLogoutListener}" title="Confirmation">
    <af:outputText value="Do you want to logout?" id="ot2"/>

The real work is done in the dialog listener in the managed bean (here called LoginLogout). The dialog listener checks if OK was clicked, and then calls the logoutTarget method with a parameter which is the target page after invalidating the session. This page is a normal html page just showing the user that his session has ended. On this page you can put a link back to the application as shown above.

public String logoutTarget(String aTarget)
  ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
  HttpServletResponse response = (HttpServletResponse) ectx.getResponse();
  String url = ectx.getRequestContextPath() + aTarget;
  HttpSession session = (HttpSession) ectx.getSession(false);
  //close session
  catch (IOException e)
  return null;

public void dialogLogoutListener(DialogEvent dialogEvent)
  if (dialogEvent.getOutcome() == DialogEvent.Outcome.ok)

If you use a jspx page which is part of  your application, the session gets invalidated but you see that url rewriting stuff is still part of the url you see in the browser.

I like it if the url looks like

so I use a normal html page.

Feel free to play with this. You only have to change the parameter in the logoutTarget(…) method call to


if you have a page Logout.jspx in your application.

3 thoughts on “Logout with confirmation dialog

    • Subu,
      are you ADF 7 from the mentioned thread?
      Anyway, the sample works for me. The thread however is a bit confusing as it was edited so some comments are out of context now. This make the thread hard to follow.
      The problem in the thread is that the target for the logout is a jspx page. If you redirect to a jspx page you essential just show the page but the work flow which is defined in the adfc-config.xml is not started. This is the reason the a click on a button does not navigate to the right target, but just shows the same page again.
      If you like the work flow to be started you have to redirect to the viewId you defined for the page in the adfc-config.xml. In my sample this would be ‘/faces/Logout’ and not ‘/faces/Logout.jspx’.
      I changed this in the blog to avoid further confusion.

  1. Hi, Timo
    I am a beginner in ADF. I like to know how to perform login and logout with ADF security using my database.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s