XPage:处理浏览器后退按钮 [英] XPages: Handle Browser Back Button

查看:41
本文介绍了XPage:处理浏览器后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Notes 表单创建了 XPage.我添加了一个执行一些逻辑的编辑按钮,然后将文档模式切换为编辑"和一个保存并关闭按钮,用于保存文档并重定向到 Notes 视图的 XPage.

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.

推荐答案

忽略请求参数对我来说不是一个选项.

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:禁用此页面的浏览器缓存

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

这篇关于XPage:处理浏览器后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆