liferayliferay-6liferay-themeliferay-ideliferay-velocity

Unable to redirect to other page in liferay


I am trying to redirect to other page using java code and don't no why its not getting redirected. the below is the following code

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);


PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute("javax.portlet.config");

String portletName = portletConfig.getPortletName();

PortletURL successPageURL = PortletURLFactoryUtil.create(
                actionRequest, portletName+ "_WAR_" + portletName + "portlet", 
                themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

successPageURL.setParameter("jspPage", LibraryConstants.PAGE_SUCCESS);
actionResponse.sendRedirect(successPageURL.toString());

it's not redirecting to the page. Please help to check if the code is correct or not.

Thanks.


Solution

  • I assume this code is in an action method or processAction method.

    Instead of re-directing from action-phase directly it would be better to use actionResponse.sendRenderParameter("jspPage", LibraryConstants.PAGE_SUCCESS) to set the jspPage to be rendered through the render or doView method.

    Also it would be helpful to check the sendRedirect documentation, where it is mentioned that it won't redirect in certain cases.

    Also please check if you get any error or warning when the code is executed.