Liferay portlet(带有 JSF)- 在重定向期间将参数从一个 bean 传递到另一个 bean

Liferay portlet (with JSF) - pass parameter from one bean to another during redirect

我需要从一个 portlet 的托管 bean(我将其称为 beanA,使用 ViewScoped)传递一个参数 (packageId),我在其中进行重定向:

    LiferayPortletURL url = PortletURLFactoryUtil.create(portletRequest,
            PortalUtil.getPortletId(portletRequest), themeDisplay
                    .getLayout().getPlid(), PortletRequest.ACTION_PHASE);   

    url.setParameter("_facesViewIdRender", "/views/esbDeployerView.xhtml");
    url.setParameter("packageId", doc.getId());
    url.setWindowState(WindowState.NORMAL);
    url.setPortletMode(PortletMode.VIEW);
    FacesContext.getCurrentInstance().getExternalContext().redirect(url.toString());

到另一个(beanB 与 ViewScoped),它由 EL 调用(那里有一个数据表并调用 #{esbPackageDetail.services})在 esbDeployerView.xhtml重定向后)。重定向后正确创建了 beanB,但是当我尝试在 @PostConstruct 方法中设置断点时,参数值为 null。

    HttpServletRequest request = PortalUtil.getHttpServletRequest((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
    HttpServletRequest oriRequest = PortalUtil.getOriginalServletRequest(request);
    String esbArchiveId = oriRequest.getParameter("packageId");

我也试过这个但是参数又是空的:

    LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    String hallo = liferayFacesContext.getRequestQueryStringParameter("packageId");     

编辑:

我也试过这个:

    boolean parameter = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("packageId"); 
    boolean parametervalue = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("cee43b8b-3719-4463-b317-e6fde80707c5");

两个结果都是假的...

这可能适用于您的情况:

您要重定向的代码示例:

String redirectURL = "public / private group" + "page_name" + "?packageId=" + doc.getId();
FacesContext.getCurrentInstance().getExternalContext().redirect(redirectURL);

获取参数的代码示例:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest httpServletRequest = (HttpServletRequest) (externalContext.getRequestMap().get("com.liferay.portal.kernel.servlet.PortletServletRequest"));
PortletRequest portletRequest = (PortletRequest) httpServletRequest.getAttribute("javax.portlet.request");

String packageId = null;
HttpServletRequest httpRequest = null;
if(portletRequest != null){
    httpRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(portletRequest));
    packageId = httpRequest.getParameter("packageId");
}

我终于明白了!问题出在第一步。有必要将 PortletRequest 设置为 PortletRequest.RENDER_PHASE 以在重定向期间保持参数有效。然后我能够像这样阅读它:

    HttpServletRequest request = PortalUtil.getHttpServletRequest((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
    String arumArchiveId = ParamUtil.getString(request, "packageId");   

@Parkash Kumar 还是谢谢你的帮助。