Access request Attributes (Set in managed bean before redirect) in Filter by precreating FacesContext
I am setting the request attribute in managed bean before redirect the request through faces-config as follows:
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("foo","bar");
return "redirect_success";
After this i m trying to access this request attribute in my filter through pre creating FacesContext
FacesContext.getCurre开发者_高级运维ntInstance().getExternalContext().getRequestMap().get("foo");
Finally not able to get this attribute in filter itself but i am able to get the same attribute again in second managed bean very easily. Is there any way to get it in filter itself?
Two ways:
Store in session and let filter remove it from session if necessary.
externalContext.getSessionMap().put("foo", "bar");
There's by the way no need to create
FacesContext
yourself in aFilter
. Just castServletRequest
toHttpServletRequest
.HttpSession session = ((HttpServletRequest) request).getSession(); String foo = (String) session.getAttribute("foo"); session.removeAttribute("foo");
Use
ExternalContext#redirect()
to add it as request parameter.externalContext.redirect("other.jsf?foo=bar");
And then in
Filter
:String foo = ((HttpServletRequest) request).getParameter("foo");
精彩评论