Julian Waibel
Julian Waibel

Reputation: 53

XPages: Handle Browser Back Button

I created a XPage for a Notes form. I added an edit-button which performs some logic and then switches the document-mode to "edit" and a save-and-close-button which saves the document and redirects to a XPage of a Notes view.

This works fine but when the browsers back-button is pressed after returning to the view, the document gets shown again in edit-mode. Is it possible to return to the document but in read-only-mode?

Because some logic is performed when pressing the edit-button and i need to ensure that this logic is also executed when the user returns to the document via browser back-button and not just jump right in the edit-mode without performing the logic.

Upvotes: 3

Views: 668

Answers (1)

Julian Waibel
Julian Waibel

Reputation: 53

Ignoring the request parameters is not an option for me.

I solved it by disabling the client browser cache (= force client browser to reload the page everytime instead of displaying a cached version of the page) and adding a "was the edit-mode entered via the edit-button?" check.

beforeRenderResponse: Disable browser cache for this page

var response:java.lang.Object = facesContext.getExternalContext().getResponse();
response.setHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past (= expired)
response.setHeader("Pragma", "no-cache"); // HTTP/1.0
response.setHeader("Cache-Control", "no-store"); // HTTP/1.1

beforePageLoad: Check if edit-mode was entered via edit-button. If not, change to read-only-mode

if (!<was edit-mode entered via edit-button?>) {
    var pagePart:string = view.getPageName() + "?";
    var documentPart:string = "documentId=" + context.getUrlParameter("documentId");
    var actionPart:string = "&action=openDocument";
    context.redirectToPage(pagePart + documentPart + actionPart);
}

Upvotes: 2

Related Questions