Skip Headers
Oracle® Application Development Framework Developer's Guide
10g Release 3 (10.1.3)
B25386-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

18.5 Creating a Logout Page

The logout page may be called from the global logout button that appears on any page that includes the global menu page. The purpose of the logout page is to provide a prompt for the user to confirm that they want to quit. If the user chooses to log out, their session is invalidated and then they are redirected back to the application's welcome page. They will have to log in again to continue the application. Figure 18-2 shows the logout page from the SRDemo application.

Figure 18-2 Sample Logout Page from SRDemo Application

Navigator showing basic model project.

To create the logout page:

  1. With the user interface project selected, open the New Gallery and select JSF JSP from the Web Tier - JSF category. In this case, it is acceptable to use JSF components.

  2. In the Create JSF JSP wizard, choose JSP Document type for the JSF JSP file type. In this case, you want to create a JSPX document that will use JSF components.

  3. On the Component Binding page, do not create a managed bean.

  4. On the Tag Libraries page of the wizard, add ADF Faces Components and ADF Faces HTML to the Selected Libraries list.

  5. Click Finish to complete the wizard and add the JSPX file to the user interface project.

  6. In the Component Palette, select the ADF Faces Core page, and drag the components Document, Form, and PanelPage so that PanelPage appears nested inside Form, and Form appears nested inside Document.

  7. Next construct the PanelPage container for the command buttons by dragging the components PanelBox, PanelHeader, PanelButtonBar so that PanelButtonBar appears nested inside PanelHeader, and PanelHeader appears nested inside PanelBox. All should be nested inside PanelPage.

  8. To create the buttons that give the user the choice whether to logout or not, drag two CommandButton components inside the PanelButtonBar.

  9. The first button should provide the logout function. You can wire it separately by creating a managed bean. For details, see Section 18.5.1, "Wiring the Logout Action".

  10. The second button should invoke an action GlobalHome to direct the user to the desired page. This action will be defined in the faces-config.xml file with a navigation rule.

Example 18-4 shows the source code from the SRDemo application's logout page. This JSPX document has no restriction on using JSF components because the page has no interaction with the security container. The action to invoke the logout function appears on the <af:commandButton> with the logout label.

Example 18-4 Sample Source from SRLogout.jspx

<af:form>
      <af:panelPage title="#{res['srlogout.pageTitle']}">
        <!--Page Content Start-->
        <af:panelBox>
          <af:panelHeader text="#{res['srlogout.subTitle']}"
                          messageType="warning">
            <af:outputText value="#{res['srlogout.text']}"/>
            <af:panelButtonBar>
              <af:commandButton text="#{res['srlogout.logout.label']}"
                                action="#{backing_SRLogout.logoutButton_action}"/>
              <af:commandButton text="#{res['srlogout.goBack.label']}"
                                action="GlobalHome"/>
            </af:panelButtonBar>
          </af:panelHeader>
        </af:panelBox>
        <!-- Page Content End -->
        ... omitting facets related to the visual design of the page ...
      </af:panelPage>
</af:form>

18.5.1 Wiring the Logout Action

To handle the logout action, the JSPX document can use a managed bean with properties that correspond to the logout page's logout command button.

To handle the logout action:

  1. In the open logout page, double-click the command button that you reserved for the logout action.

  2. In the Bind Action Property dialog, leave Method Binding selected and click New.

  3. In the Create Managed Bean dialog, define the new class file.

  4. In the generated .java file, implement the method handler for the command button that will redirect the user back to an appropriate page. See Example 18-5 for a sample.


Tip:

If your application calls the invalidate() method on the HTTP Session to terminate the current session at logoff time, it is highly recommend to use a "Redirect" to navigate back to a home page to require accessing an ADF Model binding container. The redirect to a databound page ensure that the ADF Binding Context gets created again after invalidating the HTTP Session.

Example 18-5 shows the method handler from the SRDemo application logout page's managed bean. The logoutButton_action() method invalidates the session and redirects to the home page. The security container will prompt the user to reauthenticate automatically.

Example 18-5 Sample Source from SRLogout.java

  public String logoutButton_action() throws IOException{
    ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
    HttpSession session = (HttpSession)ectx.getSession(false);
    session.invalidate();
    
    response.sendRedirect("SRWelcome.jspx");
    return null;
  }