java - Apache Wicket 口 : Display an error message when StalePageException occurs

标签 java exception exception-handling wicket wicket-6

我有一个使用 Apache Wicket 6.x 的 Java 应用程序;有时异常 StalePageException如下所述被触发并显示在日志中。但是,由于没有向用户反馈,应用程序的行为异常导致受挫。

如何捕获 StalePageException并向用户显示一条消息(最好使用反馈面板)来解释情况?

Open a stateful page in a tab/window, then copy the url from the address bar and open it in a new tab/window. Then go back to the first tab/window and try to click on any stateful link. This will lead to StalePageException.

It is thrown because Wicket detects that the same page instance has been rendered between the render of the current page and the click on the link. Wicket does this because it is not sure whether there are any changes in the page tree hierarchy between the initial rendering and the click event. It is even possible that this link is no more existing in the last version of the page, so this click could lead to ComponentNotFoundException if StalePageException is not thrown earlier.

StalePageException just leads to render of the current page. So the user will see the last version of the page and (s)he will need to click the link again.

最佳答案

您需要使用自定义 IRequestCycleListener(从 AbstractRequestCycleListener 扩展)。 覆盖 #onException() 并且如果传递的异常是 StalePageException 那么您可以使用 Session.get().error("...") 向用户报告该异常。只需确保您在当前页面中有一个 FeedbackPanel。

关于java - Apache Wicket 口 : Display an error message when StalePageException occurs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38610489/

相关文章:

C++11 标准决定 "shared_ptr(const weak_ptr<Y>& r) Throws bad_weak_ptr"

java - 通过eclipse添加项目到weblogic时出现SAXNotRecognizedException

error-handling - 有什么方法可以处理和返回领域驱动设计实体和聚合根中的错误(非异常和异常)?

java - 当第一个策略和恢复策略都失败时 Java 中的异常组合

c# - "using exceptions to control flow"示例

java - 整数对添加到哈希集java

java - 如何在一个@Async中使用不同的执行器

c++ - C++ 或 Qt 中的文件相关异常类

java - BACnet 访问远程设备

Java - 信号量中的优先级