Access request Attributes (Set in a managed bean before redirecting) to the Filter, previously creating FacesContext

I set the request attribute in a managed bean before redirecting the request through faces-config as follows:

FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("foo","bar");

return "redirect_success";

After that, I try to access this request attribute in my filter by first creating FacesContext

FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("foo");

Finally, you cannot get this attribute in the filter itself, but I can get the same attribute again in the second managed bean very easily. Is there any way to get it in the filter itself?

+3
source share
1 answer

Two ways:

  • Save the session and let the filter remove it from the session, if necessary.

    externalContext.getSessionMap().put("foo", "bar");
    

    , , FacesContext Filter. ServletRequest HttpServletRequest.

    HttpSession session = ((HttpServletRequest) request).getSession();
    String foo = (String) session.getAttribute("foo");
    session.removeAttribute("foo");
    
  • ExternalContext#redirect(), .

    externalContext.redirect("other.jsf?foo=bar");
    

    Filter:

    String foo = ((HttpServletRequest) request).getParameter("foo");
    
+4

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


All Articles