Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
972 views
in Technique[技术] by (71.8m points)

jsf 2 - JSF messages persistance

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

The problem is:

  1. user submits invalid form
  2. form redisplayed, messages not displayed to user due to using 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:

  1. user submits invalid form
  2. form redisplayed with error messages
  3. user corrects and submits valid form
  4. form redisplayed with "success" message, but also previous error messages also displayed.

How can I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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:

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...