Issue
I have a spring mvc based portlet that the content is generated based on the view returned by the @RenderMapping method. Is there a solution on how to catch the url that causes the render of portlet. because I'm using a payment system that return fields to this portlet and I want to display them in a # jsp page so In this case I should render another jsp based on the fields returned by the payment server.
thank you in advance
Solution
You can get the URL that caused the RENDER_PHASE
of the portlet lifecycle to be invoked in one of two ways:
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;
...
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String portalURL = themeDisplay.getPortalURL();
-or-
import com.liferay.portal.kernel.util.PortalUtil;
...
String portalURL = PortalUtil.getCurrentURL(renderRequest);
However I don't recommend inspecting the String representation of the URL. The Portlet API is designed in such a way that the javax.portlet.RenderURL
that invoked the portlet lifecycle can be a vendor-specific implementation detail. For example, a render URL from Liferay would be different than one from Apache Pluto. Instead, portlet developers are encouraged to use features of the Portlet API to get the values of request parameters, attributes, etc.
Perhaps you could add some detail to your question that describes exactly what aspect of the URL you are concerned about.
Answered By - Neil Griffin
Answer Checked By - Robin (JavaFixing Admin)