Search This Blog

Showing posts with label Implementing the "Clear Session" Button. Show all posts
Showing posts with label Implementing the "Clear Session" Button. Show all posts

Sunday, July 13, 2025

Implementing the "Clear Session" Button

In Oracle APEX, users interact with session state as they enter data, navigate between pages, or submit forms. Over time, session values can accumulate and affect how pages behave—especially during testing or repeated use. Implementing a "Clear Session" button is a simple and powerful way to reset the application to a clean state by clearing all session variables. This is especially useful for developers, testers, or end users who need to return to a default state without manually clearing individual items. This blog explains how to build and use a "Clear Session" button in Oracle APEX.

How to Implement a "Clear Session" Button in Oracle APEX

  1. Add a Button to Your Page

    • Open your target page in Page Designer

    • Under the Regions section, click + and add a Button

    • Set the button label to Clear Session

    • Give it a static ID like BTN_CLEAR_SESSION if you need to reference it in JavaScript

  2. Create a Dynamic Action for the Button

    • Under Dynamic Actions, click Create

    • Event: Click

    • Selection Type: Button

    • Button: Select your Clear Session button

    • Add a True Action:

      • Action: Execute PL/SQL Code

      • PL/SQL Code:

        apex_util.clear_page_cache(:APP_ID);
        
      • This clears the session state for the entire application

  3. Add a Page Redirect After Clearing

    • Add another True Action:

      • Action: Redirect to Page in This Application

      • Set the target to the page you want the user to return to, usually the home or login page

  4. Optional: Use JavaScript to Show Feedback
    You can add a spinner or notification message to indicate that the session is being cleared, depending on the user experience you want.

 The Clear Session button resets the values of FName and LName by clearing the session state.

Implementation Steps

  1. Set the Button Action to Defined by Dynamic Action.

  2. Create a Dynamic Action with the following attributes: 

    • Event: Click

    • Action: Execute PL/SQL Code

    • PL/SQL Code:

apex_util.clear_page_cache(:APP_PAGE_ID);

  • Affected Elements:

    • Selection Type: Items

    • Items: P1_FNAME, P1_LNAME

This ensures that the values in the text fields are cleared when the button is clicked.

Best Practices for a Clear Session Button

  • Use it in admin or developer-facing areas to avoid disrupting normal users unintentionally

  • Clearly label the button and optionally confirm before executing

  • Combine with a spinner or message so the user knows something is happening

  • Redirect users to a safe, known page after clearing session state

  • Only include this button where needed—not on every page

  • Avoid clearing session state while users are in the middle of data entry or transactions

Oracle APEX Documentation Links

Conclusion

A "Clear Session" button in Oracle APEX is a simple but effective tool for maintaining clean session state during development, testing, or controlled user flows. It resets the application without requiring manual item-by-item clearing and ensures predictable page behavior. By combining PL/SQL with dynamic actions and smart UX design, you can implement a safe and user-friendly reset mechanism in just a few steps.

 

Tuesday, July 1, 2025

Implementing the "Clear Session" Button

 In many Oracle APEX applications, maintaining session state can improve performance and user experience. However, there are scenarios—especially in complex forms or dashboards—where users may need to reset the current session to clear out all entered or stored values. Implementing a "Clear Session" button provides a convenient way to reset page items, filters, and internal state without requiring users to log out or manually refresh every field. This small feature can significantly reduce confusion, especially when testing or working with large datasets.

In Oracle APEX, implementing a “Clear Session” button is a helpful feature that allows users to reset all session state for a page. This is especially useful in data entry forms or dashboards where users want to clear filters, item values, or undo changes without manually refreshing each element. You can easily create this functionality using a button and a built-in URL.

To begin, go to the Page Designer and create a new Button on the desired page. You can place it in a toolbar, region, or any area that makes sense contextually. Give it a meaningful name like CLEAR_SESSION.

Under the Behavior section of the button’s properties, set the Action to Redirect to URL.

In the Target URL field, use the following format:

f?p=&APP_ID.:&APP_PAGE_ID.:&SESSION.::RESET

This URL tells APEX to reload the current application and page, but to clear the session state before doing so. The ::RESET part is what performs the session state reset. It clears all values, including page items, pagination, sorting, filters, and other APEX internal states associated with the page.

If you want to clear the entire session (for example, across multiple pages), you can use:

f?p=&APP_ID.:1:&SESSION.:RESET

This version will redirect the user to page 1 (or any other page you specify), while also performing a full application session reset.

You can style the button with a CSS class like t-Button--danger if you want to highlight it as a reset or destructive action.

Optionally, if you want to provide a confirmation before executing the action, add a Dynamic Action on the button’s click event, and use a JavaScript confirmation dialog before redirecting.

By using the built-in APEX reset functionality, you don’t need to write any PL/SQL or JavaScript logic to manually clear item values. This is a lightweight, clean, and efficient solution that enhances user experience and reduces data entry errors.

Another way of doing it:

The Clear Session button resets the values of FName and LName by clearing the session state.

Implementation Steps

  1. Set the Button Action to Defined by Dynamic Action.

  2. Create a Dynamic Action with the following attributes: 

    • Event: Click

    • Action: Execute PL/SQL Code

    • PL/SQL Code:

apex_util.clear_page_cache(:APP_PAGE_ID);

  • Affected Elements:

    • Selection Type: Items

    • Items: P1_FNAME, P1_LNAME

This ensures that the values in the text fields are cleared when the button is clicked.

Adding a "Clear Session" button gives users a fresh starting point within the application, improving usability and reducing input errors. Whether you're building administrative tools, data entry forms, or dashboards, including this functionality helps keep the interface clean and responsive. By pairing the button with proper page processes or redirection logic, you ensure that users always return to a well-defined and consistent application state.

How Do I Make a Faceted Search Map Page in Oracle APEX

Combining faceted search with a map region in Oracle APEX enables users to filter data visually and spatially at the same time. This design ...