我已经尝试了所有方法,但没有任何效果,在目标 @PostConstruct
中参数为空。
我正在发送从 BeanA 到页面(由 BeanB 支持)的重定向,并尝试从 BeanB 中提取参数。要求是不要在 URL 中添加参数。
我尝试了所有方法:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("userId", userId);
@SessionScoped
bean,ec.getFlash().put("userId", userId);
有什么建议吗? 我正在重定向:
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getExternalContext().redirect(url);
最佳答案
Portlet API 知道两个 session 范围:PORTLET_SCOPE
和 APPLICATION_SCOPE
默认桥将 session 映射中的所有属性映射到 PORTLET_SCOPE
,这意味着这些属性仅对 portlet 可见。
如果您想写入和读取所有 portlet 的 session 属性,则必须使用:
PortletSession session = ((PortletSession) FacesContext.getCurrentInstance().
getExternalContext().getSession(true));
// set
session.setAttribute(attributeName, value, PortletSession.APPLICATION_SCOPE);
// get
Object value = session.getAttribute(attributeName, PortletSession.APPLICATION_SCOPE);
在 XHTML 中,您也可以使用 #{httpSessionScope.attributeName}
。
关于JSF + Liferay : Cannot send parameters from a bean to another,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29945266/