JSF消息持久性 [英] JSF messages persistance
问题描述
我有一个viewScoped bean,它具有一些业务逻辑验证. 我使用
I have a viewScoped bean which has some business logic validation. I display the resultant errors from this validation to the page using
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, result, null));
问题是:
- 用户提交的表单无效
- 重新显示表单,由于使用PRG而未向用户显示消息
我使用以下代码行解决了这个问题:
I solved this using the following line of code:
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
现在的问题是业务逻辑验证消息持续的时间太长:
Now the problem is that the business logic validation messages persist too long:
- 用户提交的表单无效
- 重新显示错误消息的表格
- 用户更正并提交有效表格
- 重新显示成功"消息的表单,同时还会显示以前的错误消息.
我该如何解决?
推荐答案
根据您的问题评论,您正在使用Mojarra 2.0.3:
Based on your question comment, you're using Mojarra 2.0.3:
[JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0]
[javax.enterprise.resource.webcontainer.jsf.config] Initializing Mojarra 2.0.3 ( b05)
这确实是一个古老的Mojarra版本.目前已有3.5多年的历史了! (2010年7月发布).您的具体问题是由问题1751 引起的,该问题已在2.0.7/2.1中修复. .4.但是,之后还有许多其他有关Flash作用域的问题报告. Flash范围是Mojarra的较旧版本,主要存在以下主要问题:
This is really an ancient Mojarra version. It's currently over 3.5 years old already! (released July 2010). Your concrete problem is caused by specifically issue 1751 which is fixed in 2.0.7/2.1.4. There have however been many other issue reports related to the flash scope afterwards. The flash scope is in older Mojarra versions known for the following major problems:
- 问题1751-Flash范围内的消息的寿命比下一个请求更长-已在2.0.7/2.1中修复.4
- 问题2126-Flash cookie启用了数据利用-已在2.1.24/2.2.1中修复
- 问题2136-重定向到其他路径时Flash cookie不可用-已在2.1.14中修复/2.2.0
- 问题2902-Flash cookie对根应用程序使用了错误的路径-在2.1.24中已修复/2.2.1
- 问题2955-Flash有时会创建版本1 Cookie,该版本在IE< = 10中失败-已在2.1中修复.25/2.2.2
- 问题2973-会话期满后Flash会在过时的Cookie上导致NPE-已在2.1.25中修复/2.2.2
- 问题2862-过期时不会清除Flash cookie-已在2.1.27/2.2.5中修复
- issue 1751 - Flash scoped messages lives longer than next request - fixed in 2.0.7 / 2.1.4
- issue 2126 - Flash cookie enables data exploits - fixed in 2.1.24 / 2.2.1
- issue 2136 - Flash cookie not available when redirected to different path - fixed in 2.1.14 / 2.2.0
- issue 2902 - Flash cookie uses wrong path for applications on root - fixed in 2.1.24 / 2.2.1
- issue 2955 - Flash creates sometimes version1 cookies which fails in IE<=10 - fixed in 2.1.25 / 2.2.2
- issue 2973 - Flash causes NPE on stale cookies after a session expire - fixed in 2.1.25 / 2.2.2
- issue 2862 - Flash cookie not cleared when stale - fixed in 2.1.27 / 2.2.5
总而言之,可以得出的结论是,为了摆脱所有这些问题,您需要至少升级到Mojarra 2.1.27/2.2.5.
All in all, concluded can be that you'd need to upgrade to a minimum of Mojarra 2.1.27 / 2.2.5 in order to get rid of all those problems.
记录器中的JSFImplManagementDeployer
条目可识别为JBoss 6.x中的条目.古老的Mojarra 2.0.3反过来建议您仍在使用第一个JBoss 6.0.0版本.这里充满了很多错误,强烈建议升级到最新的JBoss服务器,不仅要解决这些Mojarra问题,还要解决许多其他问题.考虑升级到JBoss AS 7.3.x或EAP6.2.x.如有必要,您可以根据以下答案中的说明升级其捆绑的Mojarra:
The JSFImplManagementDeployer
entry in the logger is recognizable as the one from JBoss 6.x. The ancient Mojarra 2.0.3 in turn suggests that you're still using the very first JBoss 6.0.0 release. This is so full of bugs and it's strongly recommended to upgrade to a more recent JBoss server, not only to fix those Mojarra issues, but also many others. Consider upgrading to JBoss AS 7.3.x or EAP 6.2.x. If necessary, you can upgrade its bundled Mojarra based on the instructions in this answer: Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly.
这篇关于JSF消息持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!