liferayportlet(使用jsf)-在重定向期间将参数从一个bean传递到另一个bean

jyztefdp  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(402)

我需要从一个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());

另一个(具有viewscoped的beanb)由el调用(a在那里有一个数据表,并在重定向后调用esbdeployerview.xhtml中的#{esbpackagedetail.services})。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");

两个结果都是假的。。。

kmpatx3s

kmpatx3s1#

这可能适用于您的情况:
要重定向的代码示例:

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");
}
gv8xihay

gv8xihay2#

我终于明白了!问题出在第一步。有必要将portletrequest设置为portletrequest.render\u阶段,以便在重定向期间保持参数活动。然后我可以像这样读:

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

@帕卡什·库马尔谢谢你的帮助。

相关问题