XPages: Handle Browser Back Button

放肆的年华 提交于 2019-12-22 10:31:31

问题


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.


回答1:


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);
}


来源:https://stackoverflow.com/questions/38486022/xpages-handle-browser-back-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!