How to deal with JSF messages between page navigations (POST-REDIRECT-GET)

前端 未结 1 1827
悲哀的现实
悲哀的现实 2020-12-18 03:12

I\'m developing JSF 2 web application and using implicit navigation from page to page specifying outcome values and changing url values. I also have some Aj

相关标签:
1条回答
  • 2020-12-18 03:49

    The problem symptoms suggests that you're navigating by a redirect instead of a (default) forward by either the faces-redirect=true parameter in the outcome, or the <redirect/> entry in the navigation case, if you're still using legacy navigation rules in faces-config.xml.

    Faces messages are request scoped and are thus only available in the resource served by the current request. When navigating by a redirect, you're basically instructing the webbrowser to create a brand new request on the given URL. The faces messages are not available in that request at all.

    If redirecting is really mandatory, e.g. to accomplish the POST-Redirect-GET pattern — which is a Good Thing —, then you need to store the message in the flash scope. You can do that by calling Flash#setKeepMessages(), passing true.

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

    Note that this will fail if you're using a Mojarra version older than 2.1.14 and are redirecting to a resource in a different base folder. See also issue 2136.

    0 讨论(0)
提交回复
热议问题