I need to pass one parameter (packageId) from one portlet's managed bean (I will call it beanA , with ViewScoped) where I do redirect:
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());
to another ( beanB with ViewScoped) which is invoked by EL (a have a datatable there and call #{esbPackageDetail.services}) in esbDeployerView.xhtml after redirect). beanB is correctly created after redirect but when I try to set a breakpoint in on @PostConstruct method, the parameter value is null.
HttpServletRequest request = PortalUtil.getHttpServletRequest((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
HttpServletRequest oriRequest = PortalUtil.getOriginalServletRequest(request);
String esbArchiveId = oriRequest.getParameter("packageId");
I have tried also this but the parameter is null again:
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
String hallo = liferayFacesContext.getRequestQueryStringParameter("packageId");
EDIT:
I also tried this:
boolean parameter = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("packageId");
boolean parametervalue = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("cee43b8b-3719-4463-b317-e6fde80707c5");
both results are false...
I finally figured it out! The problem was in first step. It is necessary to set up PortletRequest to PortletRequest.RENDER_PHASE to keep a parameter alive during redirect. Then I was able to read it like:
HttpServletRequest request = PortalUtil.getHttpServletRequest((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
String arumArchiveId = ParamUtil.getString(request, "packageId");
@Parkash Kumar Thank you for your help anyway.
This might work in your case:
Code sample from where you want to redirect:
String redirectURL = "public / private group" + "page_name" + "?packageId=" + doc.getId();
FacesContext.getCurrentInstance().getExternalContext().redirect(redirectURL);
Code sample to get parameter:
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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.