javascript - 在命中服务器端业务逻辑之前捕获刷新事件
问题描述
这就是我在页面中实现 Flash 范围以确保 bean 在重定向后可用的方式。我正在使用 JBoss EAP 6 附带的 JSF 2.1.19。
page1.xhtml
<h:commandLink value="#{result.itemVO.number}" action="#{itemBean.goToSecondPage}">
<f:setPropertyActionListener target="#{itemBean.itemVO}" value="#{result.itemVO}" />
</h:commandLink>
ItemBean.Java
这是两个页面之间的通用 bean。
public String goToSecondPage() {
Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
flash.put("itemBean", this);
flash.setKeepMessages(true);
flash.keep("itemBean");
return "secondPage";
}
@PostConstruct
public void init() {
Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
ItemBean itemBean = (ItemBean) flash.get("itemBean");
//Number
itemBean.getItemVO.getNumber();
}
从 page1 重定向后,itemBean 对象在 init 方法中的 flash 中可用。
但是当我在第 2 页重新加载页面时,即使我调用 setKeepMessages(true),flash 也是空的。我根据 itemVO 在页面上加载了很多字段,但在重新加载后不存在并且页面呈现为空白。要么我想捕获重新加载事件并停止呈现页面,要么我需要找到一种方法来在重新加载的情况下保留 Flash 对象。
我已经通过这篇文章在重新加载后保留 flash 对象,但它谈到了 EL 的使用。但在我的情况下,我需要在 bean post 构造方法中访问它。
我还尝试了导航计时 api 来捕获 javascript 中的刷新事件,如此处所述。但这是在 bean 初始化之后调用的,由于一些遗留代码问题,我想避免这种情况。
解决方案
推荐阅读
- java - 使用凭证从 java 调用 web 服务
- asp.net - 创建代理服务器 - 转发所有标题、正文、所有内容,但更改 URL
- node.js - Node.js .map 函数导致快递服务器提前返回响应对象
- macos - 通过系统偏好设置applescript访问开关控制
- javascript - 创建一个 google 脚本,用于在电子表格的每一页上的同一单元格中查找和替换文本
- clickhouse - Clickhouse 中物化视图的工作原理
- python - RuntimeError:张量的元素 0 不需要 grad 并且没有用于非神经网络实现的 grad_fn
- traefik - 使用 traefik 查看超过 :80 的 traefik 仪表板
- python - 我看不到是什么触发了无效的语法错误
- python - 创建一个上传按钮并将文件作为变量读取