Passing FacesMessage to the next page

I am looking for an elegant JSF way for this and wondered if there was a common practice for this.

When I move from one page to another, I want the new page to display FacesMessage in the h: message component (actually p: message ), but it should be the same) that was transferred from the last page.

So, for example, if the user clicks the "Create Document" button, he goes to a new page with success and displays a message about successful completion on a new page. I want all my database change operations to behave this way.

It seems that FacesContext clears all messages from navigation, so my nearest solution looks like this:

  • Save the FacesMessage object in a bean session.
  • Create a checkMessage method in the bean message that calls FacesContext.getCurrentInstance (). addMessage (..) and removes the message from the bean message.
  • Put the EL link on checkMessage on the landing page.
  • Put p: message on the landing page.

This seems a bit forced - is there a better way to do this?

+4
source share
2 answers

Faces posts are really requested.

Just use the new Flash JSF 2.0 scope: Flash#setKeepMessages() :

 context.addMessage(clientId, message); context.getExternalContext().getFlash().setKeepMessages(true); // ... 

There is only one caveat in the current release of Mojarra 2.1.13: redirects must occur in the same โ€œfolderโ€ in the URL. This is recorded in the near future 2.1.14. See also number 2136 .

+11
source

Source: https://habr.com/ru/post/957674/


All Articles