0

I am trying to send an error message from back bean class to view but it shows for a second and then went away. I don't know the reason please let me know what I am doing wrong. For scope, I am using ManagedBean and RequestScoped

String msg = "Without 'Sample Id/Experiment Id' Keys file cannot proceed";
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, ""));

In my view, I am trying to get these error and these containers

<rich:messages globalOnly="true" />
<rich:messages for="gv" />

It shows these messages but doesn't stay there and vanish. Thank you in advance

1 Answers1

1

JSF messages have basically a lifetime of a single request (but you can extend this via Flash Scope in JSF2) and thus disappear after a request finished.

rich:message components get auto-updated (i.e. ajaxRendered) by default. So it's very likely, that you have some AJAX-request, that triggers right after the message was shown on your page. Because of the request-scope of messages, no more messages are available in the new request and the rich:messages get updated again with empty content.

You can verify this by using your browsers developer tools or Firebug to watch network your traffic.

Martin Höller
  • 2,714
  • 26
  • 44
  • I am trying to get back on the same view from back bean class. There is no ajax call after that. – Gulzaib Amjed Oct 24 '17 at 09:34
  • @GulzaibAmjed you write, "it shows the messages but doesn't stay there and vanish", so there must be happening something that triggers this vanishing. My guess was an AJAX update of the messages. If there is no such AJAX update, it must be on client-side, i.e. in your browser. Do you see the message in the source-code of your page (right-click -> view source)? – Martin Höller Oct 24 '17 at 10:27
  • Issue resolved You was right there was an ajax call. you gave me a solid hint for the cause. Great! – Gulzaib Amjed Oct 26 '17 at 12:57
  • If my answer was useful, please consider accepting the answer or upvoting it. Thanks. – Martin Höller Oct 26 '17 at 19:21