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
Set the Button Action to Defined by Dynamic Action.
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.
No comments:
Post a Comment