2

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?

Mark W
  • 5,416
  • 13
  • 52
  • 90
  • what are you using for showing Error message to user. Can you please share may be setting a time out for messages can help. Please share message component. – Vinayak Pingale Jan 16 '14 at 17:08
  • 2
    Are you implying that you're performing validation in action method and also calling `Flash#setKeepMessages()` when you don't need to redirect? You should call it **only** when you actually need to redirect. – BalusC Jan 16 '14 at 17:32
  • Thanks @VinayakPingale. I have updated. – Mark W Jan 16 '14 at 17:48
  • @BalusC Yes I am performing the validation in the action. I am calling Flash#setKeepMessages() just before sending the redirect: return ("myPage.jsf?faces-redirect=true"); – Mark W Jan 16 '14 at 17:49
  • It happened to us with some Mojarra implementations that messages in flash scope persisted more than they should. Which JSF impl are you dealing with? – Xtreme Biker Jan 17 '14 at 07:08
  • I'm new to JSF. Hope this gives the info you ask for: [JSFImplManagementDeployer] Initialized 3 JSF configurations: [Mojarra-1.2, MyFaces-2.0, Mojarra-2.0] also: [javax.enterprise.resource.webcontainer.jsf.config] Initializing Mojarra 2.0.3 ( b05) – Mark W Jan 17 '14 at 11:31

1 Answers1

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)

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.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452